[comp.lang.c] Microsoft C: Getting The DS & SS For A Module

cramer@kontron.UUCP (Clayton Cramer) (01/06/87)

I'm writing a program using Microsoft C and MASM which installs a new
interrupt 17 ISR.  The new ISR calls a C function.  How do I get the
DS and SS values for the C function to set before calling the C function?

If this were an ordinary assembler program calling a C function, this 
would be very easy to do, since the linker stuffs the stack into the
same segment with the data for C, but the ISR has its own DS and SS when
invoked, and the C function objects vigorously to using the DS and SS
of the ISR!

Clayton E. Cramer

Slave + firearm = free man

backman@interlan.UUCP (Larry Backman) (01/07/87)

In article <1273@kontron.UUCP> cramer@kontron.UUCP (Clayton Cramer) writes:
>I'm writing a program using Microsoft C and MASM which installs a new
>interrupt 17 ISR.  The new ISR calls a C function.  How do I get the
>DS and SS values for the C function to set before calling the C function?
>

	I've solved this problem before by calling an assembly function
	from the C module sometime during program initialization.  The
	assembly function copies both the DS and SS into variables located
	in its code segment.  Then when the ISR is invoked, it replaces
	the existing DS and SS values with the values aaved in code segment.
	For example:

	CODE SEGMENT

	save_ds		dw	?
	save_ss		dw	?

	post_init	proc 	far

	
		push	ax	
		mov	ax,ds	
		mov	cs:save_ds,ax

		mov	ax,ss
		mov	cs:save_ss,ax
		pop	ax
		
		retf
	post_init	endp	

	something_isr	proc	far

		... save registers ...
		mov	ax,cs:save_ds
		mov	ds,ax

		mov	ax,cs:save_ss
		mov	ss,ax

		....call C with correct segments

		....
		iret
	something_isr	proc	far

	A word of warning - Make sure that interrupts are off when you start
	playing with DS and SS!


			Larry Backman\
			Micom - Interlan Inc
			155 Swanson Rd.
			Boxborough Ma, 01719
			617-263-9929  x291

			ulowell  
			mit-eddie      !interlan!backman