How to call interrupt through register? [Solved]

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
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

How to call interrupt through register? [Solved]

Post 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?
Last edited by Ycep on Thu May 19, 2016 1:04 pm, edited 1 time in total.
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: How to call interrupt through register?

Post by osdever »

You're not calling interrupt with intr number, but accessing value at address intr and using it as interrupt number.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: How to call interrupt through register?

Post 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.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: How to call interrupt through register?

Post 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.
Mike Gonta
look and see - many look but few see

https://mikegonta.com
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: How to call interrupt through register?

Post 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!
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to call interrupt through register?

Post by BrightLight »

b.zaar wrote:From memory I think the int opcode = 0x20 but you can check this.
INT opcode is 0xCD.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

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

Post 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).
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: How to call interrupt through register?

Post 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...
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
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: How to call interrupt through register? [Solved]

Post 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:
"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