returned value from custom interrupt

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

returned value from custom interrupt

Post 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
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: returned value from custom interrupt

Post 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.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: returned value from custom interrupt

Post by i586coder »

Are GS,FS registers useful for my case,
and what is that registers anyway :shock:
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: returned value from custom interrupt

Post by i586coder »

ok,if we talk about registers,anyone know some documents around Intel x86-64 registers

:mrgreen:
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: returned value from custom interrupt

Post by AJ »

pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: returned value from custom interrupt

Post by pcmattman »

I would imagine the Intel manuals might be of assistance as well.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: returned value from custom interrupt

Post by i586coder »

8) links
thank you
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: returned value from custom interrupt

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: returned value from custom interrupt

Post 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 :?
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: returned value from custom interrupt

Post by AJ »

Code: Select all

-masm=intel
:wink:

This can be used directly with Combuster's suggestion of a cross compiler.

Cheers,
Adam
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: returned value from custom interrupt

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: returned value from custom interrupt

Post 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 ;))
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: returned value from custom interrupt

Post 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

Code: Select all

asm{
    mov ebx, eax
}
and in DJGPP i will use

Code: Select all

asm("movl %eax, %ebx");
:idea:
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: returned value from custom interrupt

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply