Need help making device driver call C routine 
Author Message
 Need help making device driver call C routine

OK here's the problem I'm tackling: I need a DOS device driver that
will let me gain control of a computer during boot-up.  Since I am
entirely too rusty at assembly language, I am trying to interface an
existing character device driver to a C routine.  Right now I can't
get this interface functioning.

My system is a 286 running DOS 3.3 with Borland C 2.0.

I'm pretty sure it is possible to write C code that can be called from
something as low-level as a character device driver, because I have
seen code on SIMTEL that uses C and assembly language modules to
create a block device driver for a SCSI device.  I am completely
stumped as to why I cannot do the same thing here.

The existing device driver I am modifying is condrv.sys from Michael
Tischer's _PC System Programming_ on page 172.  My C routine is named
s_ctl(), and is empty right now:

/* s_ctl.c -- Dummy C routine to call from the device driver */

void s_ctl()
        int i;  
        i = 32;


I put my hook in the device driver in the initialization routine,
since I want the C code to function on boot-up when this driver is
encountered in config.sys, and the initialization routine is
guaranteed to run at this point.

Tischer's code compiles and runs unmodified, but with my hook in
place, the routine fails at link time with:

fixup overflow at CODE:0127, target = _s_ctl

This line is right after I make my call to _s_ctl in the assembly

After reading about this error in the Borland documentation, I made
sure I compiled the C routine with the small memory model to match the
memory model specified in the assembly routine.

This is my assembly module, modified from Tischer's example:
;*  Derived from Michael Tischer's CONDRV example on page 172  *;
;*  of PC System Programming. My additions are minimal, and    *;
;*  comments near the changes start with ;PK:                  *;
;*  Sections deleted for brevity's sake marked with ...        *;

.MODEL  small

;PK: even if the EXTRN declaration is here, I get the same error.

code     segment

;PK: tell the initialization routine to expect an external C routine
EXTRN   _s_ctl:near

         assume cs:code,ds:code,es:code,ss:code

         org 0                   ;Program has no PSP therefore start
                                 ;at Offset address 0

;== Constants =========================================================
;== Data ==============================================================
;-- Header of Device Driver -------------------------------------------
;-- Jump Table for functions -------------------------
;== Routines and functions of driver ===============================

strat    proc far                ;Strategy routine
strat    endp

intr     proc far                ;Interrupt routine
intr     endp
dummy    proc near              
dummy    endp
no_sup   proc near              
no_sup   endp
store_c  proc near              
store_c  endp
read    proc near                
read    endp
read_b  proc near                
read_b  endp
del_in_b proc near              
del_in_b endp
write proc near                  
write endp
init     proc near               ;Initialization routine

        ;PK: call the external C routine
        call _s_ctl             ; no need to add sp, anything for params
        ;pop bp         ; makes no difference whether this line is
                        ;here or not

         mov  word ptr es:[di+end_adr],offset init  ;Set End-Address of
         mov  es:[di+end_adr+2],cs                  ;the driver

         xor  ax,ax              ;everything o.k.
         ret                     ;back to caller

init     endp


code     ends

That about it.  Here's the spccfg.cfg file used to control Borland C
when compiling my C module:


I sure would appreciate some pointers here.

Pierce Krouse -- DTM Corp., Austin, TX (512)339-2922x320

WWW: http://www.*-*-*.com/ ~pierce/

Thu, 24 Jul 1997 06:16:33 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Need help to access command line in device driver

2. need help on writing device driver with 32bits fat

3. need help on cdrom device driver

4. Calling device drivers in Assy.

5. Calling a Device Driver from Assembly

6. Need help: call fortran routine in C programs

7. Real-Time Embedded OS Device Drivers for LAN/WAN Devices

8. Real-Time Embedded OS Device Drivers for LAN/WAN Devices

9. Need a sample of Block Device Driver

10. NASM: I need an example device driver

11. ! Device Driver Developers Needed

12. **Device Driver Developers Needed


Powered by phpBB® Forum Software