DF-2427 / df_pre.c
/* * DF-2426 / DF-2427 verification harness -- PREAMBLE (shared by both * evidence packs; byte-identical df_pre.c/df_post.c in both). * * This file is concatenated (gen.sh, run on the guest) BEFORE a * verbatim copy of sys/dev/disk/amd/amd.c and AFTER it df_post.c is * appended; the result is compiled into the kernel as * dev/disk/amd/dfamd_harness.c (conf/files entry "standard"). * * The X86_64_GENERIC kernel does not configure "device amd" * (dev/disk/amd/amd.c is "optional amd" in conf/files), so the * verbatim copy inside this TU is the only compiled instance of the * driver. Nothing in the driver source is renamed or edited; it is * byte-for-byte the audited file (sha256-gated by build.sh against * the audit tree). * * Interposition model * ------------------- * 1. xpt_done(): amd_action() completes CCBs through it; the shim * (df_post.c) records the status instead of handing a fabricated * CCB to the live CAM transport, and passes through to the real * xpt_done when the harness is not armed (nothing ever calls the * driver for real in this guest: no AMD53c974 hardware exists). * * 2. Register access. The amd53c974 accessors amd_read8/amd_write8 * (amd.h:560-579) expand to bus_space_read_1()/bus_space_write_1() * with (amd->tag, amd->bsh); on x86_64 a MEM-space tag makes those * plain volatile memory accesses at (bsh + offset) * (sys/cpu/x86_64/include/bus_dma.h:134-142). The harness points * tag/bsh at an emulated register block (dfh_regs[]), so ALL * register traffic in the verbatim driver executes the real inline * bus_space code against fabricated MMIO. * * The ONE exception is the SCSI FIFO register (SCSIFIFOREG, +08h): * on the real chip each read pops the next FIFO byte (amd_Reselect * reads it twice in a row: reselect-ID byte, then identify byte). * A flat memory cell cannot model that, so this preamble includes * the VERBATIM amd.h first (consuming its amd_read8/amd_write8 * macro definitions), then redefines just those two macros to FIFO * pop/push shims for port 0x08 and to the plain memory path for * every other register. Because amd.h is include-guarded, the * verbatim amd.c that follows picks up these interposed macros; * its source text is untouched. */ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/types.h> #include <sys/queue.h> #include <sys/malloc.h> #include <sys/conf.h> #include <sys/device.h> #include <sys/lock.h> #include <sys/sysctl.h> #include <sys/bus.h> #include <sys/rman.h> #include <sys/thread2.h> #include <vm/vm.h> #include <vm/pmap.h> #include <machine/clock.h> #include <bus/cam/cam.h> #include <bus/cam/cam_ccb.h> #include <bus/cam/cam_sim.h> #include <bus/cam/cam_xpt.h> #include <bus/cam/cam_xpt_sim.h> #include <bus/cam/cam_xpt_periph.h> #include <bus/cam/cam_debug.h> #include <bus/cam/scsi/scsi_all.h> #include <bus/cam/scsi/scsi_message.h> #include <bus/pci/pcivar.h> #include <bus/pci/pcireg.h> /* ---- interposition of external symbols (see header comment) ---- */ #define xpt_done dfh_xpt_done /* shim prototypes (implemented in df_post.c) */ static void dfh_xpt_done(union ccb *ccb); /* ---- consume the VERBATIM amd.h, then interpose its I/O macros ---- */ #include "amd.h" #undef amd_read8 #undef amd_write8 #define amd_read8(amd, port) dfh_amd_read8((amd), (port)) #define amd_write8(amd, port, val) dfh_amd_write8((amd), (port), (val)) static u_int8_t dfh_amd_read8(struct amd_softc *amd, u_int port); static void dfh_amd_write8(struct amd_softc *amd, u_int port, u_int8_t val); /* * ==================== VERBATIM amd.c FOLLOWS ==================== */ |