diff options
author | wpaul <wpaul@FreeBSD.org> | 2004-08-01 20:04:31 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 2004-08-01 20:04:31 +0000 |
commit | b9b3caf965335247a6b02d871301c0e4c4bb87f6 (patch) | |
tree | d0b9b243dad5e4df570a3cdb81c557ba28056697 /sys/compat/ndis/subr_ntoskrnl.c | |
parent | b8bae5430cbfa33d7ab39405a204b1f7f416bcca (diff) | |
download | FreeBSD-src-b9b3caf965335247a6b02d871301c0e4c4bb87f6.zip FreeBSD-src-b9b3caf965335247a6b02d871301c0e4c4bb87f6.tar.gz |
Big mess 'o changes:
- Give ndiscvt(8) the ability to process a .SYS file directly into
a .o file so that we don't have to emit big messy char arrays into
the ndis_driver_data.h file. This behavior is currently optional, but
may become the default some day.
- Give ndiscvt(8) the ability to turn arbitrary files into .ko files
so that they can be pre-loaded or kldloaded. (Both this and the
previous change involve using objcopy(1)).
- Give NdisOpenFile() the ability to 'read' files out of kernel memory
that have been kldloaded or pre-loaded, and disallow the use of
the normal vn_open() file opening method during bootstrap (when no
filesystems have been mounted yet). Some people have reported that
kldloading if_ndis.ko works fine when the system is running multiuser
but causes a panic when the modile is pre-loaded by /boot/loader. This
happens with drivers that need to use NdisOpenFile() to access
external files (i.e. firmware images). NdisOpenFile() won't work
during kernel bootstrapping because no filesystems have been mounted.
To get around this, you can now do the following:
o Say you have a firmware file called firmware.img
o Do: ndiscvt -f firmware.img -- this creates firmware.img.ko
o Put the firmware.img.ko in /boot/kernel
o add firmware.img_load="YES" in /boot/loader.conf
o add if_ndis_load="YES" and ndis_load="YES" as well
Now the loader will suck the additional file into memory as a .ko. The
phony .ko has two symbols in it: filename_start and filename_end, which
are generated by objcopy(1). ndis_open_file() will traverse each module
in the module list looking for these symbols and, if it finds them, it'll
use them to generate the file mapping address and length values that
the caller of NdisOpenFile() wants.
As a bonus, this will even work if the file has been statically linked
into the kernel itself, since the "kernel" module is searched too.
(ndiscvt(8) will generate both filename.o and filename.ko for you).
- Modify the mechanism used to provide make-pretend FASTCALL support.
Rather than using inline assembly to yank the first two arguments
out of %ecx and %edx, we now use the __regparm__(3) attribute (and
the __stdcall__ attribute) and use some macro magic to re-order
the arguments and provide dummy arguments as needed so that the
arguments passed in registers end up in the right place. Change
taken from DragonflyBSD version of the NDISulator.
Diffstat (limited to 'sys/compat/ndis/subr_ntoskrnl.c')
-rw-r--r-- | sys/compat/ndis/subr_ntoskrnl.c | 139 |
1 files changed, 48 insertions, 91 deletions
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c index b8c85f4..2a39374 100644 --- a/sys/compat/ndis/subr_ntoskrnl.c +++ b/sys/compat/ndis/subr_ntoskrnl.c @@ -62,9 +62,9 @@ __FBSDID("$FreeBSD$"); #include <sys/rman.h> #include <compat/ndis/pe_var.h> +#include <compat/ndis/ntoskrnl_var.h> #include <compat/ndis/hal_var.h> #include <compat/ndis/resource_var.h> -#include <compat/ndis/ntoskrnl_var.h> #include <compat/ndis/ndis_var.h> #define __regparm __attribute__((regparm(3))) @@ -81,8 +81,10 @@ __stdcall static ndis_status ntoskrnl_ansi_to_unicode(ndis_unicode_string *, ndis_ansi_string *, uint8_t); __stdcall static void *ntoskrnl_iobuildsynchfsdreq(uint32_t, void *, void *, uint32_t, uint32_t *, void *, void *); -__stdcall static uint32_t ntoskrnl_iofcalldriver(/*void *, void * */ void); -__stdcall static void ntoskrnl_iofcompletereq(/*void *, uint8_t*/ void); +__fastcall static uint32_t ntoskrnl_iofcalldriver(REGARGS2(void *dobj, + void *irp)); +__fastcall static void ntoskrnl_iofcompletereq(REGARGS2(void *irp, + uint8_t prioboost)); __stdcall static uint32_t ntoskrnl_waitforobjs(uint32_t, nt_dispatch_header **, uint32_t, uint32_t, uint32_t, uint8_t, int64_t *, wait_block *); @@ -117,19 +119,22 @@ __stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *, lookaside_alloc_func *, lookaside_free_func *, uint32_t, size_t, uint32_t, uint16_t); __stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *); -__stdcall static slist_entry *ntoskrnl_push_slist(/*slist_header *, - slist_entry * */ void); -__stdcall static slist_entry *ntoskrnl_pop_slist(/*slist_header * */ void); -__stdcall static slist_entry *ntoskrnl_push_slist_ex(/*slist_header *, - slist_entry *,*/ kspin_lock *); -__stdcall static slist_entry *ntoskrnl_pop_slist_ex(/*slist_header *, - kspin_lock * */void); -__stdcall static uint32_t - ntoskrnl_interlock_inc(/*volatile uint32_t * */ void); -__stdcall static uint32_t - ntoskrnl_interlock_dec(/*volatile uint32_t * */ void); -__stdcall static void ntoskrnl_interlock_addstat(/*uint64_t, - uint32_t*/ void); +__fastcall static slist_entry *ntoskrnl_push_slist(REGARGS2(slist_header *head, + slist_entry *entry)); +__fastcall static slist_entry *ntoskrnl_pop_slist(REGARGS1(slist_header + *head)); +__fastcall static slist_entry + *ntoskrnl_push_slist_ex(REGARGS2(slist_header *head, + slist_entry *entry), kspin_lock *lock); +__fastcall static slist_entry + *ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, + kspin_lock *lock)); +__fastcall static uint32_t + ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend)); +__fastcall static uint32_t + ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend)); +__fastcall static void ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, + uint32_t inc)); __stdcall static void ntoskrnl_freemdl(ndis_buffer *); __stdcall static uint32_t ntoskrnl_sizeofmdl(void *, size_t); __stdcall static void ntoskrnl_build_npaged_mdl(ndis_buffer *); @@ -162,7 +167,7 @@ __stdcall static uint32_t ntoskrnl_release_mutex(kmutant *, uint8_t); __stdcall static uint32_t ntoskrnl_read_mutex(kmutant *); __stdcall static ndis_status ntoskrnl_objref(ndis_handle, uint32_t, void *, uint8_t, void **, void **); -__stdcall static void ntoskrnl_objderef(/*void * */ void); +__fastcall static void ntoskrnl_objderef(REGARGS1(void *object)); __stdcall static uint32_t ntoskrnl_zwclose(ndis_handle); static uint32_t ntoskrnl_dbgprint(char *, ...); __stdcall static void ntoskrnl_debugger(void); @@ -293,25 +298,15 @@ ntoskrnl_iobuildsynchfsdreq(func, dobj, buf, len, off, event, status) return(NULL); } -__stdcall static uint32_t -ntoskrnl_iofcalldriver(/*dobj, irp*/) +__fastcall static uint32_t +ntoskrnl_iofcalldriver(REGARGS2(void *dobj, void *irp)) { - void *dobj; - void *irp; - - __asm__ __volatile__ ("" : "=c" (dobj), "=d" (irp)); - return(0); } -__stdcall static void -ntoskrnl_iofcompletereq(/*irp, prioboost*/) +__fastcall static void +ntoskrnl_iofcompletereq(REGARGS2(void *irp, uint8_t prioboost)) { - void *irp; - uint8_t prioboost; - - __asm__ __volatile__ ("" : "=c" (irp), "=d" (prioboost)); - return; } @@ -957,49 +952,38 @@ ntoskrnl_delete_nplookaside(lookaside) * declared to be _fastcall in Windows. gcc 3.4 is supposed * to have support for this calling convention, however we * don't have that version available yet, so we kludge things - * up using some inline assembly. + * up using __regparm__(3) and some argument shuffling. */ -__stdcall static slist_entry * -ntoskrnl_push_slist(/*head, entry*/ void) +__fastcall static slist_entry * +ntoskrnl_push_slist(REGARGS2(slist_header *head, slist_entry *entry)) { - slist_header *head; - slist_entry *entry; slist_entry *oldhead; - __asm__ __volatile__ ("" : "=c" (head), "=d" (entry)); - oldhead = (slist_entry *)FASTCALL3(ntoskrnl_push_slist_ex, head, entry, &ntoskrnl_global); return(oldhead); } -__stdcall static slist_entry * -ntoskrnl_pop_slist(/*head*/ void) +__fastcall static slist_entry * +ntoskrnl_pop_slist(REGARGS1(slist_header *head)) { - slist_header *head; slist_entry *first; - __asm__ __volatile__ ("" : "=c" (head)); - first = (slist_entry *)FASTCALL2(ntoskrnl_pop_slist_ex, head, &ntoskrnl_global); return(first); } -__stdcall static slist_entry * -ntoskrnl_push_slist_ex(/*head, entry,*/ lock) - kspin_lock *lock; +__fastcall static slist_entry * +ntoskrnl_push_slist_ex(REGARGS2(slist_header *head, + slist_entry *entry), kspin_lock *lock) { - slist_header *head; - slist_entry *entry; slist_entry *oldhead; uint8_t irql; - __asm__ __volatile__ ("" : "=c" (head), "=d" (entry)); - irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL); oldhead = ntoskrnl_pushsl(head, entry); FASTCALL2(hal_unlock, lock, irql); @@ -1007,16 +991,12 @@ ntoskrnl_push_slist_ex(/*head, entry,*/ lock) return(oldhead); } -__stdcall static slist_entry * -ntoskrnl_pop_slist_ex(/*head, lock*/ void) +__fastcall static slist_entry * +ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, kspin_lock *lock)) { - slist_header *head; - kspin_lock *lock; slist_entry *first; uint8_t irql; - __asm__ __volatile__ ("" : "=c" (head), "=d" (lock)); - irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL); first = ntoskrnl_popsl(head); FASTCALL2(hal_unlock, lock, irql); @@ -1024,62 +1004,42 @@ ntoskrnl_pop_slist_ex(/*head, lock*/ void) return(first); } -__stdcall void -ntoskrnl_lock_dpc(/*lock*/ void) +__fastcall void +ntoskrnl_lock_dpc(REGARGS1(kspin_lock *lock)) { - kspin_lock *lock; - - __asm__ __volatile__ ("" : "=c" (lock)); - while (atomic_cmpset_acq_int((volatile u_int *)lock, 0, 1) == 0) /* sit and spin */; return; } -__stdcall void -ntoskrnl_unlock_dpc(/*lock*/ void) +__fastcall void +ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *lock)) { - kspin_lock *lock; - - __asm__ __volatile__ ("" : "=c" (lock)); - atomic_store_rel_int((volatile u_int *)lock, 0); return; } -__stdcall static uint32_t -ntoskrnl_interlock_inc(/*addend*/ void) +__fastcall static uint32_t +ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend)) { - volatile uint32_t *addend; - - __asm__ __volatile__ ("" : "=c" (addend)); - atomic_add_long((volatile u_long *)addend, 1); return(*addend); } -__stdcall static uint32_t -ntoskrnl_interlock_dec(/*addend*/ void) +__fastcall static uint32_t +ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend)) { - volatile uint32_t *addend; - - __asm__ __volatile__ ("" : "=c" (addend)); - atomic_subtract_long((volatile u_long *)addend, 1); return(*addend); } -__stdcall static void -ntoskrnl_interlock_addstat(/*addend, inc*/) +__fastcall static void +ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, uint32_t inc)) { - uint64_t *addend; - uint32_t inc; uint8_t irql; - __asm__ __volatile__ ("" : "=c" (addend), "=d" (inc)); - irql = FASTCALL2(hal_lock, &ntoskrnl_global, DISPATCH_LEVEL); *addend += inc; FASTCALL2(hal_unlock, &ntoskrnl_global, irql); @@ -1510,14 +1470,11 @@ ntoskrnl_objref(handle, reqaccess, otype, accessmode, object, handleinfo) return(NDIS_STATUS_SUCCESS); } -__stdcall static void -ntoskrnl_objderef(/*object*/void) +__fastcall static void +ntoskrnl_objderef(REGARGS1(void *object)) { - void *object; nt_objref *nr; - __asm__ __volatile__ ("" : "=c" (object)); - nr = object; TAILQ_REMOVE(&ntoskrnl_reflist, nr, link); free(nr, M_DEVBUF); |