Turbo C - ISR chaining? (Developers)
> Hi, is there some helper function/macro in Borland BC/TC for chaining ISR
> (DJGPP has such feature)? I'd like to hook and let my ISR code be called
> first, without modifying registers and when done call the old ISR with
> original registers. Problem is that BC automatically saves and restores all
> registers in ISR in its prolog/epilog code and when i do
> ISR()
> {
> mycode;
> oldisr();
> }
> then oldisr gets changed registers by my code and registers that oldisr
> sets are vanished by epilog code that restores all, so I'd need to call it
> in order
> ISR()
> { // epilog save regs
> mycode;
> } // epilog restore regs
> oldisr(); // call old ISR with original regs
>
> I prefer to do as much as possible in C and avoid ASM but if BC/TC have any
> helper I'll have to do ASM. BTW can BC/TC do naked function?
There's something that may let you access the registers on the stack:
This seems to work with Turbo C++ 1.01:
#include <dos.h>
#include <stdio.h>
typedef struct {
int bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
} IREGS;
void interrupt far isr(IREGS ir)
{
ir.ax = ~ir.ax;
}
int main(void)
{
struct REGPACK regs;
int i;
setvect(0, isr);
memset(®s, 0, sizeof regs);
for (i = 0; i < 4; i++)
{
regs.r_ax = i;
intr(0, ®s);
printf("%04X\n", regs.r_ax);
}
return 0;
}
OW has something similar:
#include <i86.h>
void __interrupt int10(union INTPACK r)
{
...
}
Please check documentation and look this up in more detail.
With this you should be able to examine and modify the return address on the stack and make your ISR "chain" to another.
Complete thread:
- Turbo C - ISR chaining? - RayeR, 05.12.2020, 00:26 (Developers)
- Turbo C - ISR chaining? - tkchia, 05.12.2020, 07:09
- Turbo C - ISR chaining? - RayeR, 06.12.2020, 18:25
- Turbo C - ISR chaining? - alexfru, 05.12.2020, 09:48
- Turbo C - ISR chaining? - RayeR, 06.12.2020, 18:29
- Turbo C - ISR chaining? - alexfru, 07.12.2020, 06:32
- Turbo C - ISR chaining? - tom, 07.12.2020, 14:42
- Turbo C - ISR chaining? - alexfru, 07.12.2020, 06:32
- Turbo C - ISR chaining? - RayeR, 06.12.2020, 18:29
- Turbo C - ISR chaining? - tkchia, 05.12.2020, 07:09