Index: conf/files =================================================================== RCS file: /home/ncvs/src/sys/conf/files,v retrieving revision 1.1266 diff -u -r1.1266 files --- conf/files 27 Jan 2008 01:10:41 -0000 1.1266 +++ conf/files 2 Feb 2008 10:16:12 -0000 @@ -643,6 +643,7 @@ dev/ep/if_ep_mca.c optional ep mca dev/ep/if_ep_pccard.c optional ep pccard dev/esp/ncr53c9x.c optional esp +dev/evilmem/evilmem.c standard dev/ex/if_ex.c optional ex dev/ex/if_ex_isa.c optional ex isa dev/ex/if_ex_pccard.c optional ex pccard Index: dev/evilmem/evilmem.c =================================================================== RCS file: dev/evilmem/evilmem.c diff -N dev/evilmem/evilmem.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/evilmem/evilmem.c 2 Feb 2008 10:27:59 -0000 @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2008 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +static d_open_t evilmem_open; +static d_mmap_t evilmem_mmap; + +static struct cdevsw evilmem_cdevsw = { + .d_version = D_VERSION, + .d_flags = D_PSEUDO, + .d_open = evilmem_open, + .d_mmap = evilmem_mmap, + .d_name = "evilmem", +}; + +static struct cdev *evilmem_dev; +static struct evilmem *evilmem; + +static int +evilmem_open(struct cdev *dev, int flags, int devtype, struct thread *td) +{ + + if (flags & FWRITE) + return (EPERM); + + return (0); +} + +static int +evilmem_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, + int prot) +{ + + if (prot & VM_PROT_WRITE) + return (EPERM); + if (offset != 0) + return (EINVAL); + if (evilmem == NULL) + return (ENXIO); + *paddr = vtophys(evilmem); + return (0); +} + +void +evilmem_tick(void) +{ + struct timespec ts; + + /* + * XXXRW: This synchronization is likely bogus. + */ + nanotime(&ts); + atomic_add_rel_int(&evilmem->em_generation_before, 1); + evilmem->em_time = ts; + atomic_add_rel_int(&evilmem->em_generation_after, 1); +} + +static void +evilmem_init(void *unused) +{ + + evilmem = (struct evilmem *)kmem_malloc(kmem_map, PAGE_SIZE, + M_NOWAIT); + if (evilmem == NULL) + panic("evilmem_init: kmem_malloc"); + bzero(evilmem, PAGE_SIZE); + evilmem->em_magic = EVILMEM_MAGIC; + + evilmem_dev = make_dev(&evilmem_cdevsw, 0, UID_ROOT, GID_KMEM, + 0444, "evilmem"); +} +SYSINIT(evilmem_init, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, evilmem_init, NULL); Index: dev/evilmem/evilmem.h =================================================================== RCS file: dev/evilmem/evilmem.h diff -N dev/evilmem/evilmem.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/evilmem/evilmem.h 2 Feb 2008 10:37:41 -0000 @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2008 Robert N. M. Watson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must 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 _DEV_EVILMEM_EVILMEM_H_ +#define _DEV_EVILMEM_EVILMEM_H_ + +#define EVILMEM_MAGIC 0x0123456776543210LL + +/* + * Open /dev/evilmem, and mmap() offset 0 with PROT_READ. Cast the result to + * struct evilmem, check the magic. Before reading the time, read + * em_generation. Then read the time, and read generation again. If the two + * generations don't match, repeat. + */ +struct evilmem { + u_int64_t em_magic; + volatile int em_generation_before; + volatile struct timespec em_time; + volatile int em_generation_after; +}; + +#ifdef _KERNEL +void evilmem_tick(void); +#endif + +#endif /* !_DEV_EVILMEM_EVILMEM_H_ */ Index: kern/kern_tc.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_tc.c,v retrieving revision 1.179 diff -u -r1.179 kern_tc.c --- kern/kern_tc.c 2 Jan 2008 18:48:27 -0000 1.179 +++ kern/kern_tc.c 2 Feb 2008 10:15:03 -0000 @@ -21,6 +21,8 @@ #include #include +#include + /* * A large step happens on boot. This constant detects such steps. * It is relatively small so that ntp_update_second gets called enough @@ -806,6 +808,12 @@ cpu_tick_calibrate(0); last_calib = time_uptime; } + + /* + * XXXRW: Really, we should plop it down directly but I let phk do + * the work and it seems to run ok. + */ + evilmem_tick(); } static void