www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/09/09:03:43

Sender: ccwu AT lilly DOT ping DOT de
Message-ID: <3465C25A.7C1CBABF@ping.de>
Date: Sun, 09 Nov 1997 15:02:02 +0100
From: Cheng-Chang Wu <C DOT Wu AT ping DOT de>
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Can I do printf in callback handler (interrupt handler)?

This is a multi-part message in MIME format.

--------------4C6C6CAE4340F9F323E555E8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,
  I write a DJGPP program to communicate with my 16bit dos program. At
first the DJGPP program install a realmode callback ( an isr), and pass
the callback address to my
16bit dos program. When the realmode callback receives requests, it
setups registers and stack and transfers the control to a C function
(cnc_main()). So far so good, I can
do sin(), cos() in mein C function. But it causes Page fault
when it executes printf(). Why is printf() so special? How can I get
around the problem? The attached code is a part of my programs.

Cheng-Chang

--------------4C6C6CAE4340F9F323E555E8
Content-Type: text/plain; charset=iso-8859-1; name="fc_isr.s"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="fc_isr.s"

.file "fc_isr.s"
.global _fc_callback_isr
.global _fc_setup_callback_segs
.text
_fc_callback_isr:
        cli
        # save registers
	pushw	%ds
	pushl	%esi
        pushw   %es
	pushl	%edi

	# setup %ds to point to our data segment (=selector of callback-reg)
        movw %cs:_fc_ds, %ds

        # save locked protected mode stack provided by DPMI host
        movw    %ss, %ax
        movw    %ax, _dpmi_ss
        movl    %esp, %eax
        movl    %eax, _dpmi_esp

        # setup stack for cnc_main()
	movw %cs:_fc_es, %es
	movw %cs:_fc_ss, %ax
	movl %cs:_fc_esp, %ebp
	movw	%ax, %ss
	movl	%ebp, %esp

        call    _cnc_main
        movw    %ax, %dx                # ¶Ç¦^­È¼È©ñ©óDX¤¤

        # restore locked protected mode stack provided by DPMI host
        movl    _dpmi_esp, %ebp
        movw    _dpmi_ss, %ax
        movw    %ax, %ss
        movl    %ebp, %esp

        popl    %edi
        popw    %es
        popl    %esi
        popw    %ds

        cld
        lodsw
        movw    %ax, %es:0x2A(%edi)      # ip
        lodsw   %ax
        movw    %ax, %es:0x2C(%edi)      # cs
        movw    $4, %ax
        addw    %ax, %es:0x2E(%edi)      # sp

        movw    %dx, %es:0x1C(%edi)      # ax
        iret

_fc_setup_callback_segs:
        movw    %ds, %ax
        movw    %ax, _fc_ds
	movw	%es, %ax
	movw	%ax, _fc_es
	movw	%ss, _fc_ss
	movl	%esp, %eax
	subl	$800, %eax
	movl	%eax, _fc_esp
        ret

.data
_fc_ds:         .short 0
_fc_es:		.short 0
_fc_ss:		.short 0
_fc_esp:	.long  0
_dpmi_ss:       .short 0
_dpmi_esp:      .long  0

--------------4C6C6CAE4340F9F323E555E8
Content-Type: text/plain; charset=us-ascii; name="cnc_main.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="cnc_main.c"

#include <sys/farptr.h>
#include "fc_cnc.h"
#include "stdio.h"
#include "math.h"
extern int cnc_main() asm("_cnc_main");
int cnc_main()
{
  if(1 == _farpeekw(channel, 0))
    return 1;
  if(2 == _farpeekw(channel, 0))
    return 2;
  if(3 == _farpeekw(channel, 0))
    return ( (int) (50*sin(2.0)));
  printf("TEST");
  return(-1);
}


--------------4C6C6CAE4340F9F323E555E8--


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019