Page 1 of 1
returned value from custom interrupt
Posted: Thu Sep 25, 2008 11:51 am
by i586coder
Hello folks,
I have trouble with interrupts
i use this code in TC++3.1 to make custom interrupt
Code: Select all
void set_int( void far interrupt p() ,char intNo ){
_AX=0;
_ES=_AX;
_AL=intNo;
_BL=4;
asm mul bl
_BX=_AX;
_SI=(int)p;
asm{ mov es:[bx],si
add bx,2
mov ax,cs
mov es:[bx],ax
}
}
void interrupt myInterrupt(){
switch(_AH){
case 0x1: printf("subInt #00"); break;
case 0x2: _DX+=2; break;
case 0x3: _CX=_BH+_BL; break;
}
}
main(){
set_int(myInterrupt,0x88);
int sum;
asm{mov ah,3
mov bh,2
mov bl,4
int 0x88
mov word ptr[sum],cx
}
printf("%d",sum);}
result must be 2+4=6
my problem is
1) what is the best registers must use to pass parameter & the best to returne value
2) is it safe to use stack as parameter
ThAnKs
Re: returned value from custom interrupt
Posted: Thu Sep 25, 2008 12:28 pm
by System123
The parameters are usually passed through the AX and DX registers. You can use all of them if you need but AX is the most common. Yes the stack can be used as long as you don't push or pop from it in between calling and executing the interrupt.
Re: returned value from custom interrupt
Posted: Thu Sep 25, 2008 12:44 pm
by i586coder
Are
GS,FS registers useful for my case,
and what is that registers anyway
Re: returned value from custom interrupt
Posted: Thu Sep 25, 2008 12:47 pm
by i586coder
ok,if we talk about registers,anyone know some documents around Intel x86-64 registers
Re: returned value from custom interrupt
Posted: Thu Sep 25, 2008 1:15 pm
by AJ
Re: returned value from custom interrupt
Posted: Fri Sep 26, 2008 12:21 am
by pcmattman
I would imagine the Intel manuals might be of assistance as well.
Re: returned value from custom interrupt
Posted: Fri Sep 26, 2008 2:55 am
by i586coder
links
thank you
Re: returned value from custom interrupt
Posted: Fri Sep 26, 2008 4:19 am
by Combuster
From what I recall, Turbo C normally compiles an interrupt call to preserve registers. That means you can
a) Not return anything directly
b) Those saved registers are most likely on the stack, so you can not easily pass anything that way.
Also Turbo C compiles for a 286 architecture. It can't do 32-bit code, let alone 64-bit code.
If you're serious about OS development you should grab a
GCC Cross-Compiler instead.
Re: returned value from custom interrupt
Posted: Fri Sep 26, 2008 5:41 am
by i586coder
I tried DJGPP before, but I have a serious problem with
AT&T assembly syntax. since i am advanced coder with Intel syntax
Re: returned value from custom interrupt
Posted: Fri Sep 26, 2008 5:50 am
by AJ
This can be used directly with Combuster's suggestion of a cross compiler.
Cheers,
Adam
Re: returned value from custom interrupt
Posted: Sat Sep 27, 2008 6:47 am
by Combuster
You don't need to use GNU AS. Nasm, Yasm and Fasm are popular alternatives (and they all do intel syntax).
Still, AS in intel mode is awkward to use since it occasionally uses different names for opcodes compared to the intel manuals (especially the kernel-level instructions)
Re: returned value from custom interrupt
Posted: Sat Sep 27, 2008 6:57 am
by inflater
Combuster wrote:Nasm, Yasm and Fasm
No FASM if he wants to combine his code with any other compiler, let it be ASM, C, pascal or any other. (Well, if he wants to know the magic of hardcore hex-editing, file offsets and copying raw chunks of data, let him
)
Re: returned value from custom interrupt
Posted: Sat Sep 27, 2008 7:31 am
by i586coder
All i need to know if there is any method to access assembly inside C (DJGPP)compiler instead of
use external assembler like NASM with Intel syntax
in TC i use
and in DJGPP i will use
Re: returned value from custom interrupt
Posted: Sat Sep 27, 2008 10:13 am
by Combuster