Page 1 of 1

How to call interrupt through register? [Solved]

Posted: Thu May 19, 2016 12:14 pm
by Ycep
Hi, i was wondering how could i call interrupt in protected mode.
So i tried to switch to real mode, execute interrupt, and switch back to protected mode.
Well i use MS VS 2010 Ultimate C++ compiler and i got error "C2415: improper operand type".
This is what i do:

Code: Select all

void intupt(char intr) // Call interrupt function, INTR is number of interrupt
{
	pm2rm(); //Protected Mode to Real Mode
	__asm
	{
		mov al, [intr] //Put INTR to register AL
		int al // Call interrupt using register AL
	}
	rm2pm(); //Real Mode to Protected Mode
}
Please help me since i placed release date to tommorow #-o !
How to fix this?

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 12:26 pm
by osdever
You're not calling interrupt with intr number, but accessing value at address intr and using it as interrupt number.

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 12:47 pm
by b.zaar

Code: Select all

    int al
I don't think that is a legal instruction, you are also overwriting your ax/eax value before the interrupt. You might be able to define some asm data bytes like

Code: Select all

asm {
    push ax/eax
    mov al, intr
    mov [intByte], intr
    pop ax/eax
    db 0x20 
intByte: 
    db 0x00 
}
From memory I think the int opcode = 0x20 but you can check this. Another option would be to create the code as a Macro like

Code: Select all

#define INT(intr) asm{int intr}
and use this straight in your function. You could extend this macro to set the registers with values too.

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 12:52 pm
by mikegonta
lukaandjelkovic wrote:Please help me since i placed release date to tommorow
In SudoBIOS the interrupt number is a stack parameter used to index a copy of the original real mode IDT entry which is saved in a
global variable which is then used as an indirect call (after pushing the flags) to simulate an int instruction.

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 1:04 pm
by Ycep
b.zaar wrote:

Code: Select all

#define INT(intr) asm{int intr}
and use this straight in your function. You could extend this macro to set the registers with values too.
I like nice people. Thanks Zaar!

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 2:35 pm
by BrightLight
b.zaar wrote:From memory I think the int opcode = 0x20 but you can check this.
INT opcode is 0xCD.

Re: How to call interrupt through register? [Solved]

Posted: Thu May 19, 2016 2:52 pm
by ~
lukaandjelkovic wrote:Hi, i was wondering how could i call interrupt in protected mode.
So i tried to switch to real mode, execute interrupt, and switch back to protected mode.
Well i use MS VS 2010 Ultimate C++ compiler and i got error "C2415: improper operand type".
This is what i do:

Code: Select all

void intupt(char intr) // Call interrupt function, INTR is number of interrupt
{
	pm2rm(); //Protected Mode to Real Mode
	__asm
	{
		mov al, [intr] //Put INTR to register AL
		int al // Call interrupt using register AL
	}
	rm2pm(); //Real Mode to Protected Mode
}
Please help me since i placed release date to tommorow #-o !
How to fix this?
Looks like you cannot use a register with the INT instructions (INT imm8, INT 33, INTO).
http://pdos.csail.mit.edu/6.828/2006/readings/i386/INT.htm

You must be trying to dynamically call interrupts from a routine given the interrupt number.

The best way to do it is to keep your routine that calls interrupts, then you must perform exactly the actions that the INT instruction performs, and Calculate the Address of the Interrupt Vector and do a Manual Far Call or a Manual Far Jump to that address.

Instead of modifying the opcode of the INT instruction, just emulate that instruction.
Then you can call that interrupt manually given the register with the INT number you want to use.


However, try to use the stack or reload the register you want to use with the value the actual Interrupt Service expects, once you calculate the far address, or you will get in the way of the parameters for the actual interrupts and it will sill be a bad, dirty implementation to fix for tomorrow.




________________________
If you try to implement self-modifying code, it will surely become unstable and will just not last in your project (it will be deleted after proving that it is unstable).

Re: How to call interrupt through register?

Posted: Thu May 19, 2016 3:35 pm
by b.zaar
omarrx024 wrote:
b.zaar wrote:From memory I think the int opcode = 0x20 but you can check this.
INT opcode is 0xCD.
Cheers, I was off by a mile...

Re: How to call interrupt through register? [Solved]

Posted: Fri May 20, 2016 7:40 am
by Combuster
lukaandjelkovic wrote:Please help me since i placed release date to tommorow #-o !
Oh dear, I guess you should read Beginner Mistakes and be prepared for probably the most important learning moment :wink: