2003-12-11 22:38:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2003
|
|
|
|
* Bill Paul <wpaul@windriver.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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/queue.h>
|
2004-01-02 04:31:06 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
2003-12-11 22:38:14 +00:00
|
|
|
#include <stdlib.h>
|
2005-10-26 18:46:27 +00:00
|
|
|
#include <stddef.h>
|
2003-12-11 22:38:14 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2004-08-01 20:04:31 +00:00
|
|
|
#include <libgen.h>
|
2003-12-11 22:38:14 +00:00
|
|
|
#include <err.h>
|
2004-08-01 20:04:31 +00:00
|
|
|
#include <ctype.h>
|
2003-12-11 22:38:14 +00:00
|
|
|
|
|
|
|
#include <compat/ndis/pe_var.h>
|
|
|
|
|
|
|
|
#include "inf.h"
|
|
|
|
|
|
|
|
static int insert_padding(void **, int *);
|
|
|
|
extern const char *__progname;
|
|
|
|
|
|
|
|
/*
|
2004-08-02 18:54:01 +00:00
|
|
|
* Sections within Windows PE files are defined using virtual
|
|
|
|
* and physical address offsets and virtual and physical sizes.
|
|
|
|
* The physical values define how the section data is stored in
|
|
|
|
* the executable file while the virtual values describe how the
|
|
|
|
* sections will look once loaded into memory. It happens that
|
|
|
|
* the linker in the Microsoft(r) DDK will tend to generate
|
|
|
|
* binaries where the virtual and physical values are identical,
|
|
|
|
* which means in most cases we can just transfer the file
|
|
|
|
* directly to memory without any fixups. This is not always
|
|
|
|
* the case though, so we have to be prepared to handle files
|
|
|
|
* where the in-memory section layout differs from the disk file
|
|
|
|
* section layout.
|
2003-12-11 22:38:14 +00:00
|
|
|
*
|
2004-08-02 18:54:01 +00:00
|
|
|
* There are two kinds of variations that can occur: the relative
|
|
|
|
* virtual address of the section might be different from the
|
|
|
|
* physical file offset, and the virtual section size might be
|
|
|
|
* different from the physical size (for example, the physical
|
|
|
|
* size of the .data section might be 1024 bytes, but the virtual
|
|
|
|
* size might be 1384 bytes, indicating that the data section should
|
|
|
|
* actually use up 1384 bytes in RAM and be padded with zeros). What we
|
|
|
|
* do is read the original file into memory and then make an in-memory
|
|
|
|
* copy with all of the sections relocated, re-sized and zero padded
|
|
|
|
* according to the virtual values specified in the section headers.
|
|
|
|
* We then emit the fixed up image file for use by the if_ndis driver.
|
|
|
|
* This way, we don't have to do the fixups inside the kernel.
|
2003-12-11 22:38:14 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-02 18:54:01 +00:00
|
|
|
#define ROUND_DOWN(n, align) (((uintptr_t)n) & ~((align) - 1l))
|
|
|
|
#define ROUND_UP(n, align) ROUND_DOWN(((uintptr_t)n) + (align) - 1l, \
|
|
|
|
(align))
|
2003-12-11 22:38:14 +00:00
|
|
|
|
|
|
|
#define SET_HDRS(x) \
|
|
|
|
dos_hdr = (image_dos_header *)x; \
|
|
|
|
nt_hdr = (image_nt_header *)(x + dos_hdr->idh_lfanew); \
|
2005-10-26 18:46:27 +00:00
|
|
|
sect_hdr = IMAGE_FIRST_SECTION(nt_hdr);
|
2003-12-11 22:38:14 +00:00
|
|
|
|
2010-01-02 11:05:34 +00:00
|
|
|
static int
|
|
|
|
insert_padding(void **imgbase, int *imglen)
|
2003-12-11 22:38:14 +00:00
|
|
|
{
|
|
|
|
image_section_header *sect_hdr;
|
|
|
|
image_dos_header *dos_hdr;
|
|
|
|
image_nt_header *nt_hdr;
|
|
|
|
image_optional_header opt_hdr;
|
|
|
|
int i = 0, sections, curlen = 0;
|
2004-08-02 18:54:01 +00:00
|
|
|
int offaccum = 0, oldraddr, oldrlen;
|
2003-12-11 22:38:14 +00:00
|
|
|
uint8_t *newimg, *tmp;
|
|
|
|
|
|
|
|
newimg = malloc(*imglen);
|
|
|
|
|
|
|
|
if (newimg == NULL)
|
|
|
|
return(ENOMEM);
|
|
|
|
|
|
|
|
bcopy(*imgbase, newimg, *imglen);
|
|
|
|
curlen = *imglen;
|
|
|
|
|
|
|
|
if (pe_get_optional_header((vm_offset_t)newimg, &opt_hdr))
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
sections = pe_numsections((vm_offset_t)newimg);
|
|
|
|
|
|
|
|
SET_HDRS(newimg);
|
|
|
|
|
|
|
|
for (i = 0; i < sections; i++) {
|
|
|
|
oldraddr = sect_hdr->ish_rawdataaddr;
|
|
|
|
oldrlen = sect_hdr->ish_rawdatasize;
|
2004-08-02 18:54:01 +00:00
|
|
|
sect_hdr->ish_rawdataaddr = sect_hdr->ish_vaddr;
|
|
|
|
offaccum += ROUND_UP(sect_hdr->ish_vaddr - oldraddr,
|
|
|
|
opt_hdr.ioh_filealign);
|
|
|
|
offaccum +=
|
|
|
|
ROUND_UP(sect_hdr->ish_misc.ish_vsize,
|
|
|
|
opt_hdr.ioh_filealign) -
|
|
|
|
ROUND_UP(sect_hdr->ish_rawdatasize,
|
|
|
|
opt_hdr.ioh_filealign);
|
|
|
|
tmp = realloc(newimg, *imglen + offaccum);
|
|
|
|
if (tmp == NULL) {
|
|
|
|
free(newimg);
|
|
|
|
return(ENOMEM);
|
2003-12-11 22:38:14 +00:00
|
|
|
}
|
2004-08-02 18:54:01 +00:00
|
|
|
newimg = tmp;
|
|
|
|
SET_HDRS(newimg);
|
|
|
|
sect_hdr += i;
|
2003-12-11 22:38:14 +00:00
|
|
|
bzero(newimg + sect_hdr->ish_rawdataaddr,
|
|
|
|
ROUND_UP(sect_hdr->ish_misc.ish_vsize,
|
|
|
|
opt_hdr.ioh_filealign));
|
|
|
|
bcopy((uint8_t *)(*imgbase) + oldraddr,
|
|
|
|
newimg + sect_hdr->ish_rawdataaddr, oldrlen);
|
|
|
|
sect_hdr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(*imgbase);
|
|
|
|
|
|
|
|
*imgbase = newimg;
|
|
|
|
*imglen += offaccum;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2004-08-01 20:04:31 +00:00
|
|
|
fprintf(stderr, "Usage: %s [-O] [-i <inffile>] -s <sysfile> "
|
2004-01-02 23:35:57 +00:00
|
|
|
"[-n devname] [-o outfile]\n", __progname);
|
2004-08-01 20:04:31 +00:00
|
|
|
fprintf(stderr, " %s -f <firmfile>\n", __progname);
|
|
|
|
|
2003-12-11 22:38:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-08-01 20:04:31 +00:00
|
|
|
static void
|
|
|
|
bincvt(char *sysfile, char *outfile, void *img, int fsize)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
char tname[] = "/tmp/ndiscvt.XXXXXX";
|
|
|
|
char sysbuf[1024];
|
|
|
|
FILE *binfp;
|
|
|
|
|
|
|
|
mkstemp(tname);
|
|
|
|
|
|
|
|
binfp = fopen(tname, "a+");
|
|
|
|
if (binfp == NULL)
|
|
|
|
err(1, "opening %s failed", tname);
|
|
|
|
|
|
|
|
if (fwrite(img, fsize, 1, binfp) != 1)
|
|
|
|
err(1, "failed to output binary image");
|
|
|
|
|
|
|
|
fclose(binfp);
|
|
|
|
|
|
|
|
outfile = strdup(basename(outfile));
|
|
|
|
if (strchr(outfile, '.'))
|
|
|
|
*strchr(outfile, '.') = '\0';
|
|
|
|
|
|
|
|
snprintf(sysbuf, sizeof(sysbuf),
|
2005-02-19 07:37:01 +00:00
|
|
|
#ifdef __i386__
|
2004-08-01 20:04:31 +00:00
|
|
|
"objcopy -I binary -O elf32-i386-freebsd -B i386 %s %s.o\n",
|
2005-02-19 07:37:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __amd64__
|
2010-11-01 20:20:31 +00:00
|
|
|
"objcopy -I binary -O elf64-x86-64-freebsd -B i386 %s %s.o\n",
|
2005-02-19 07:37:01 +00:00
|
|
|
#endif
|
2004-08-01 20:04:31 +00:00
|
|
|
tname, outfile);
|
|
|
|
printf("%s", sysbuf);
|
|
|
|
system(sysbuf);
|
|
|
|
unlink(tname);
|
|
|
|
|
|
|
|
ptr = tname;
|
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '/' || *ptr == '.')
|
|
|
|
*ptr = '_';
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(sysbuf, sizeof(sysbuf),
|
2008-04-15 04:17:13 +00:00
|
|
|
"objcopy --redefine-sym _binary_%s_start=ndis_%s_drv_data_start "
|
2004-08-01 20:04:31 +00:00
|
|
|
"--strip-symbol _binary_%s_size "
|
2008-04-15 04:17:13 +00:00
|
|
|
"--redefine-sym _binary_%s_end=ndis_%s_drv_data_end %s.o %s.o\n",
|
2004-08-01 20:04:31 +00:00
|
|
|
tname, sysfile, tname, tname, sysfile, outfile, outfile);
|
|
|
|
printf("%s", sysbuf);
|
|
|
|
system(sysbuf);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
firmcvt(char *firmfile)
|
|
|
|
{
|
|
|
|
char *basefile, *outfile, *ptr;
|
|
|
|
char sysbuf[1024];
|
|
|
|
|
2005-02-19 07:37:01 +00:00
|
|
|
outfile = strdup(basename(firmfile));
|
2004-08-01 20:04:31 +00:00
|
|
|
basefile = strdup(outfile);
|
|
|
|
|
|
|
|
snprintf(sysbuf, sizeof(sysbuf),
|
2005-02-19 07:37:01 +00:00
|
|
|
#ifdef __i386__
|
2004-08-01 20:04:31 +00:00
|
|
|
"objcopy -I binary -O elf32-i386-freebsd -B i386 %s %s.o\n",
|
2005-02-19 07:37:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __amd64__
|
2010-11-01 20:20:31 +00:00
|
|
|
"objcopy -I binary -O elf64-x86-64-freebsd -B i386 %s %s.o\n",
|
2005-02-19 07:37:01 +00:00
|
|
|
#endif
|
2004-08-01 20:04:31 +00:00
|
|
|
firmfile, outfile);
|
|
|
|
printf("%s", sysbuf);
|
|
|
|
system(sysbuf);
|
|
|
|
|
|
|
|
ptr = firmfile;
|
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '/' || *ptr == '.')
|
|
|
|
*ptr = '_';
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
ptr = basefile;
|
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '/' || *ptr == '.')
|
|
|
|
*ptr = '_';
|
|
|
|
else
|
|
|
|
*ptr = tolower(*ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(sysbuf, sizeof(sysbuf),
|
|
|
|
"objcopy --redefine-sym _binary_%s_start=%s_start "
|
|
|
|
"--strip-symbol _binary_%s_size "
|
|
|
|
"--redefine-sym _binary_%s_end=%s_end %s.o %s.o\n",
|
|
|
|
firmfile, basefile, firmfile, firmfile,
|
|
|
|
basefile, outfile, outfile);
|
|
|
|
ptr = sysbuf;
|
|
|
|
printf("%s", sysbuf);
|
|
|
|
system(sysbuf);
|
|
|
|
|
|
|
|
snprintf(sysbuf, sizeof(sysbuf),
|
|
|
|
"ld -Bshareable -d -warn-common -o %s.ko %s.o\n",
|
|
|
|
outfile, outfile);
|
|
|
|
printf("%s", sysbuf);
|
|
|
|
system(sysbuf);
|
|
|
|
|
|
|
|
free(basefile);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-12-11 22:38:14 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2004-08-01 20:04:31 +00:00
|
|
|
FILE *fp, *outfp;
|
|
|
|
int i, bin = 0;
|
|
|
|
void *img;
|
|
|
|
int n, fsize, cnt;
|
|
|
|
unsigned char *ptr;
|
|
|
|
char *inffile = NULL, *sysfile = NULL;
|
|
|
|
char *outfile = NULL, *firmfile = NULL;
|
|
|
|
char *dname = NULL;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
while((ch = getopt(argc, argv, "i:s:o:n:f:O")) != -1) {
|
2003-12-11 22:38:14 +00:00
|
|
|
switch(ch) {
|
2004-08-01 20:04:31 +00:00
|
|
|
case 'f':
|
|
|
|
firmfile = optarg;
|
|
|
|
break;
|
2003-12-11 22:38:14 +00:00
|
|
|
case 'i':
|
|
|
|
inffile = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sysfile = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
outfile = optarg;
|
|
|
|
break;
|
2004-01-02 04:31:06 +00:00
|
|
|
case 'n':
|
|
|
|
dname = optarg;
|
|
|
|
break;
|
2004-08-01 20:04:31 +00:00
|
|
|
case 'O':
|
|
|
|
bin = 1;
|
|
|
|
break;
|
2003-12-11 22:38:14 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-01 20:04:31 +00:00
|
|
|
if (firmfile != NULL)
|
|
|
|
firmcvt(firmfile);
|
|
|
|
|
2003-12-11 22:38:14 +00:00
|
|
|
if (sysfile == NULL)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
/* Open the .SYS file and load it into memory */
|
|
|
|
fp = fopen(sysfile, "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
err(1, "opening .SYS file '%s' failed", sysfile);
|
|
|
|
fseek (fp, 0L, SEEK_END);
|
|
|
|
fsize = ftell (fp);
|
|
|
|
rewind (fp);
|
|
|
|
img = calloc(fsize, 1);
|
|
|
|
n = fread (img, fsize, 1, fp);
|
2012-11-15 15:05:57 +00:00
|
|
|
if (n == 0)
|
|
|
|
err(1, "reading .SYS file '%s' failed", sysfile);
|
2003-12-11 22:38:14 +00:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (insert_padding(&img, &fsize)) {
|
|
|
|
fprintf(stderr, "section relocation failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outfile == NULL || strcmp(outfile, "-") == 0)
|
|
|
|
outfp = stdout;
|
|
|
|
else {
|
|
|
|
outfp = fopen(outfile, "w");
|
|
|
|
if (outfp == NULL)
|
|
|
|
err(1, "opening output file '%s' failed", outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outfp, "\n/*\n");
|
|
|
|
fprintf(outfp, " * Generated from %s and %s (%d bytes)\n",
|
2004-01-02 04:31:06 +00:00
|
|
|
inffile == NULL ? "<notused>" : inffile, sysfile, fsize);
|
2003-12-11 22:38:14 +00:00
|
|
|
fprintf(outfp, " */\n\n");
|
|
|
|
|
2004-01-02 04:31:06 +00:00
|
|
|
if (dname != NULL) {
|
|
|
|
if (strlen(dname) > IFNAMSIZ)
|
|
|
|
err(1, "selected device name '%s' is "
|
|
|
|
"too long (max chars: %d)", dname, IFNAMSIZ);
|
|
|
|
fprintf (outfp, "#define NDIS_DEVNAME \"%s\"\n", dname);
|
2004-01-02 21:13:21 +00:00
|
|
|
fprintf (outfp, "#define NDIS_MODNAME %s\n\n", dname);
|
2004-01-02 04:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inffile == NULL) {
|
2004-03-07 02:49:06 +00:00
|
|
|
fprintf (outfp, "#ifdef NDIS_REGVALS\n");
|
2003-12-11 22:38:14 +00:00
|
|
|
fprintf (outfp, "ndis_cfg ndis_regvals[] = {\n");
|
2004-01-02 04:31:06 +00:00
|
|
|
fprintf (outfp, "\t{ NULL, NULL, { 0 }, 0 }\n");
|
2004-03-07 02:49:06 +00:00
|
|
|
fprintf (outfp, "#endif /* NDIS_REGVALS */\n");
|
2003-12-11 22:38:14 +00:00
|
|
|
|
|
|
|
fprintf (outfp, "};\n\n");
|
|
|
|
} else {
|
|
|
|
fp = fopen(inffile, "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
err(1, "opening .INF file '%s' failed", inffile);
|
|
|
|
|
|
|
|
|
|
|
|
inf_parse(fp, outfp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
fprintf(outfp, "\n#ifdef NDIS_IMAGE\n");
|
2004-08-01 20:04:31 +00:00
|
|
|
|
|
|
|
if (bin) {
|
|
|
|
sysfile = strdup(basename(sysfile));
|
2006-09-21 01:48:47 +00:00
|
|
|
ptr = (unsigned char *)sysfile;
|
2004-08-01 20:04:31 +00:00
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '.')
|
|
|
|
*ptr = '_';
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
fprintf(outfp,
|
2008-04-15 04:17:13 +00:00
|
|
|
"\nextern unsigned char ndis_%s_drv_data_start[];\n",
|
2004-08-01 20:04:31 +00:00
|
|
|
sysfile);
|
|
|
|
fprintf(outfp, "static unsigned char *drv_data = "
|
2008-04-15 04:17:13 +00:00
|
|
|
"ndis_%s_drv_data_start;\n\n", sysfile);
|
2004-08-01 20:04:31 +00:00
|
|
|
bincvt(sysfile, outfile, img, fsize);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
fprintf(outfp, "\nextern unsigned char drv_data[];\n\n");
|
2003-12-18 21:47:14 +00:00
|
|
|
|
|
|
|
fprintf(outfp, "__asm__(\".data\");\n");
|
Next step on the road to IRPs: create and use an imitation of the
Windows DRIVER_OBJECT and DEVICE_OBJECT mechanism so that we can
simulate driver stacking.
In Windows, each loaded driver image is attached to a DRIVER_OBJECT
structure. Windows uses the registry to match up a given vendor/device
ID combination with a corresponding DRIVER_OBJECT. When a driver image
is first loaded, its DriverEntry() routine is invoked, which sets up
the AddDevice() function pointer in the DRIVER_OBJECT and creates
a dispatch table (based on IRP major codes). When a Windows bus driver
detects a new device, it creates a Physical Device Object (PDO) for
it. This is a DEVICE_OBJECT structure, with semantics analagous to
that of a device_t in FreeBSD. The Windows PNP manager will invoke
the driver's AddDevice() function and pass it pointers to the DRIVER_OBJECT
and the PDO.
The AddDevice() function then creates a new DRIVER_OBJECT structure of
its own. This is known as the Functional Device Object (FDO) and
corresponds roughly to a private softc instance. The driver uses
IoAttachDeviceToDeviceStack() to add this device object to the
driver stack for this PDO. Subsequent drivers (called filter drivers
in Windows-speak) can be loaded which add themselves to the stack.
When someone issues an IRP to a device, it travel along the stack
passing through several possible filter drivers until it reaches
the functional driver (which actually knows how to talk to the hardware)
at which point it will be completed. This is how Windows achieves
driver layering.
Project Evil now simulates most of this. if_ndis now has a modevent
handler which will use MOD_LOAD and MOD_UNLOAD events to drive the
creation and destruction of DRIVER_OBJECTs. (The load event also
does the relocation/dynalinking of the image.) We don't have a registry,
so the DRIVER_OBJECTS are stored in a linked list for now. Eventually,
the list entry will contain the vendor/device ID list extracted from
the .INF file. When ndis_probe() is called and detectes a supported
device, it will create a PDO for the device instance and attach it
to the DRIVER_OBJECT just as in Windows. ndis_attach() will then call
our NdisAddDevice() handler to create the FDO. The NDIS miniport block
is now a device extension hung off the FDO, just as it is in Windows.
The miniport characteristics table is now an extension hung off the
DRIVER_OBJECT as well (the characteristics are the same for all devices
handled by a given driver, so they don't need to be per-instance.)
We also do an IoAttachDeviceToDeviceStack() to put the FDO on the
stack for the PDO. There are a couple of fake bus drivers created
for the PCI and pccard buses. Eventually, there will be one for USB,
which will actually accept USB IRP.s
Things should still work just as before, only now we do things in
the proper order and maintain the correct framework to support passing
IRPs between drivers.
Various changes:
- corrected the comments about IRQL handling in subr_hal.c to more
accurately reflect reality
- update ndiscvt to make the drv_data symbol in ndis_driver_data.h a
global so that if_ndis_pci.o and/or if_ndis_pccard.o can see it.
- Obtain the softc pointer from the miniport block by referencing
the PDO rather than a private pointer of our own (nmb_ifp is no
longer used)
- implement IoAttachDeviceToDeviceStack(), IoDetachDevice(),
IoGetAttachedDevice(), IoAllocateDriverObjectExtension(),
IoGetDriverObjectExtension(), IoCreateDevice(), IoDeleteDevice(),
IoAllocateIrp(), IoReuseIrp(), IoMakeAssociatedIrp(), IoFreeIrp(),
IoInitializeIrp()
- fix a few mistakes in the driver_object and device_object definitions
- add a new module, kern_windrv.c, to handle the driver registration
and relocation/dynalinkign duties (which don't really belong in
kern_ndis.c).
- made ndis_block and ndis_chars in the ndis_softc stucture pointers
and modified all references to it
- fixed NdisMRegisterMiniport() and NdisInitializeWrapper() so they
work correctly with the new driver_object mechanism
- changed ndis_attach() to call NdisAddDevice() instead of ndis_load_driver()
(which is now deprecated)
- used ExAllocatePoolWithTag()/ExFreePool() in lookaside list routines
instead of kludged up alloc/free routines
- added kern_windrv.c to sys/modules/ndis/Makefile and files.i386.
2005-02-08 17:23:25 +00:00
|
|
|
fprintf(outfp, "__asm__(\".globl drv_data\");\n");
|
2003-12-18 21:47:14 +00:00
|
|
|
fprintf(outfp, "__asm__(\".type drv_data, @object\");\n");
|
|
|
|
fprintf(outfp, "__asm__(\".size drv_data, %d\");\n", fsize);
|
|
|
|
fprintf(outfp, "__asm__(\"drv_data:\");\n");
|
2003-12-11 22:38:14 +00:00
|
|
|
|
|
|
|
ptr = img;
|
|
|
|
cnt = 0;
|
|
|
|
while(cnt < fsize) {
|
2003-12-18 21:47:14 +00:00
|
|
|
fprintf (outfp, "__asm__(\".byte ");
|
|
|
|
for (i = 0; i < 10; i++) {
|
2003-12-11 22:38:14 +00:00
|
|
|
cnt++;
|
|
|
|
if (cnt == fsize) {
|
2003-12-18 21:47:14 +00:00
|
|
|
fprintf(outfp, "0x%.2X\");\n", ptr[i]);
|
2003-12-11 22:38:14 +00:00
|
|
|
goto done;
|
2003-12-18 21:47:14 +00:00
|
|
|
} else {
|
|
|
|
if (i == 9)
|
|
|
|
fprintf(outfp, "0x%.2X\");\n", ptr[i]);
|
|
|
|
else
|
|
|
|
fprintf(outfp, "0x%.2X, ", ptr[i]);
|
|
|
|
}
|
2003-12-11 22:38:14 +00:00
|
|
|
}
|
2003-12-18 21:47:14 +00:00
|
|
|
ptr += 10;
|
2003-12-11 22:38:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
fprintf(outfp, "#endif /* NDIS_IMAGE */\n");
|
2004-08-01 20:04:31 +00:00
|
|
|
|
2003-12-11 22:38:14 +00:00
|
|
|
if (fp != NULL)
|
|
|
|
fclose(fp);
|
|
|
|
fclose(outfp);
|
|
|
|
free(img);
|
|
|
|
exit(0);
|
|
|
|
}
|