Message-Id: <5.0.2.1.2.20011125104031.009d1910@pop.gmx.net> X-Sender: martinSteuer AT gmx DOT de@pop.gmx.net X-Mailer: QUALCOMM Windows Eudora Version 5.0.2 Date: Sun, 25 Nov 2001 11:34:00 +0100 To: djgpp AT delorie DOT com From: Martin Steuer Subject: Re: Problems with gdb??? In-Reply-To: <1858-Sat24Nov2001212931+0200-eliz@is.elta.co.il> References: <5 DOT 0 DOT 2 DOT 1 DOT 2 DOT 20011124192647 DOT 009e02e0 AT pop DOT gmx DOT net> <5 DOT 0 DOT 2 DOT 1 DOT 2 DOT 20011124192647 DOT 009e02e0 AT pop DOT gmx DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Pleasy reply also directly to me, thanks At 21:29 24.11.2001 +0200, you wrote: >If the crashes are accompanied by the normal DJGPP crash message with >registers and EIP traceback, please post here one of these messages >in its entirety. While composing this message i found a problem within the wrapper's code and fixed this but now the situation gets even more worse: Under bare DOS the program crashes without being debugged (SIGSEGV) in a call to getch() at getch()+153 (this is after the installation of the IRQ Handler) which i use to loop a sound until one presses a key. DS to GS are all zero and the stack selector is invalid. At least i'm now sure that the problem lies in my code... >Please tell more details; it's hard to answer that question because >it's too general. Debugging programs that hook hardware interrupts >is a bit tricky, but should in general work. >To give a more specific answer, we need to know what hardware >interrupts does your program hook, and how (in protected mode, real >mode, or both). Oh i suspected that there would be no easy way ;-) In my test program i'm hooking the SoundBlaster interrupt, in my case IRQ5 (INT 0D). I'm handling the interrupt completly without chaining to the previous handler in pmode. All memory accessed by the handler is locked. >A source of your wrapper function might be useful. Ok, if you have time here is it: wrapper.S: ------ #include "irq.h" .text .global _irqwrapper, __immediate_addr, __old_handler_off, __old_handler_sel .global __irqwrapper_end /* Will call the previously installed IRQ Handler if the C-Routine returns */ /* nonzero, else the old routine wont be called */ _irqwrapper: pushal pushw %ds pushw %es pushw %fs pushw %gs cs: movw (___djgpp_ds_alias),%ax /* set up ds correctly */ movw %ax,%ds movw %ax,%es movw %ax,%fs movw %ax,%gs movw %ss,%ax /* save old stack in ax, ebx */ movl %esp,%ebx movl $_st,%edx movl $-2,%ecx xor %esi,%esi _stack_search: /* find a free stack */ addl $2,%ecx cmpl $MAXSTACKS * 2,%ecx je _outofstacks cmpl 12(%edx,%ecx,8),%esi jnz _stack_search incl 12(%edx,%ecx,8) /* indicate stack is in use */ movw 4(%edx,%ecx,8),%ss /* set up locked stack */ movl 8(%edx,%ecx,8),%esp /* load size of stack */ decl %esp andl $0xfffffffc,%esp /* be sure its dword aligned */ pushl %ecx /* save index */ pushl %eax /* old ss */ pushl %ebx /* old esp */ .byte 0xb8 /* movw __immediate_addr,%eax */ __immediate_addr: .long 0x0 call *%eax /* call the irq handler */ popl %ebx /* old esp now in ebx */ popl %ecx /* old ss */ popl %esi /* get the old index into _st */ cli movl %ebx,%esp movw %cx,%ss /* DPMI IRQ Stack restored */ movl $_st,%edx decl 12(%edx,%esi,8) /* stack is free for use again */ orl %eax,%eax /* shell we call the previous handler? */ jz _outofstacks /* no */ popw %gs popw %fs popw %es popw %ds popal .byte 0xea /* far jump to previous handler */ __old_handler_off: .long 0x0 __old_handler_sel: .word 0x0 _outofstacks: popw %gs popw %fs popw %es popw %ds popal sti iret __irqwrapper_end: ------ Here comes the struct i'm using for handling the stacks: ------ struct stackInfo { void* addr; // holds address relative to ds (normal C Pointer) int sel; // holds the selector used to access the stack int size; // size of stack int free; // 0 indicates stack is free }; typedef struct stackInfo stacks[MAXSTACKS]; ------ _st is of type stacks. Now allocate_locked_stack() which is called MAXSTACKS-times: ------ static int firstcall_to_allocate_locked_stack = 1; // Returns selector for this stack or otherwise -1 int allocate_locked_stack(unsigned size) { int i,sel; long addr; void* h; if (firstcall_to_allocate_locked_stack) { firstcall_to_allocate_locked_stack = 0; LOCK_VARIABLE(st); for (i=0;i