Bochs output
Bochs output
Hey guys, I'm trying to implement interrupts now and have some questions.
I can send interrupts out (either with a divide by 0 or using inline assembly) and they look like they are handled properly on the screen, because on my screen, bochs prints out "Interrupt: 3," which is what I programmed.
However, when I look at the bochs console output, it spams out the following message until I turn the machine off:
00013509987e[CPU ] branch_near: offset outside of CS limits
This message only shows up when I use inline assembly to generate the interrupts.
If I put a divide by zero in my code however, it spams the message "interrupt: 0" on screen until I turn the machine off.
Could anyone give me some advice as to why this is happening?
I can send interrupts out (either with a divide by 0 or using inline assembly) and they look like they are handled properly on the screen, because on my screen, bochs prints out "Interrupt: 3," which is what I programmed.
However, when I look at the bochs console output, it spams out the following message until I turn the machine off:
00013509987e[CPU ] branch_near: offset outside of CS limits
This message only shows up when I use inline assembly to generate the interrupts.
If I put a divide by zero in my code however, it spams the message "interrupt: 0" on screen until I turn the machine off.
Could anyone give me some advice as to why this is happening?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
https://sourceforge.net/projects/hexciting/
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Bochs output
What's you inline code? Also, can we see your handler and perhaps the way you set it up?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Bochs output
well
i assume when you have handled the interupt you are just returning "iretd" ( if 32 bit )
The problem is very simple in that content
lets assume it looks like this:
then it execute you handle with at the end does "iretd" with retuns to the address at cs:(e)ip. but the cs:(e)ip is the address where the div happend = a loop .
so to bypass this , as a solution : you will have to know what is the distance regiser ( in the example it is ax), after you have found out, you are suposed to change that regiser to "0" ( if we assume you just would handle the calculation) and then gets the cs:(e)ip, advance ( depending on if it is a 32 bit or a 16 bit) ip to the next instruction .
KMT dk
i assume when you have handled the interupt you are just returning "iretd" ( if 32 bit )
The problem is very simple in that content
lets assume it looks like this:
Code: Select all
xor cx,cx
mov ax,0x0001
div ax,cl ; diving with 0 error.
so to bypass this , as a solution : you will have to know what is the distance regiser ( in the example it is ax), after you have found out, you are suposed to change that regiser to "0" ( if we assume you just would handle the calculation) and then gets the cs:(e)ip, advance ( depending on if it is a 32 bit or a 16 bit) ip to the next instruction .
KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
Re: Bochs output
I agree with kmdtk. Following the Intel specs, a divide by zero is an exception with the classification 'fault'. Faults are, according to the intel manuals, restartable since it can be corrected. The instruction pointer put on the stack still points to the instruction that caused the fault.
Secondly, the reasson why Bochs gives you "branch_near: offset outside of CS limits" has something to do with the jump (eip + offset >= segment limit) or the segment limit of the codesegment is to small. Doesn't have to be a problem though...
Secondly, the reasson why Bochs gives you "branch_near: offset outside of CS limits" has something to do with the jump (eip + offset >= segment limit) or the segment limit of the codesegment is to small. Doesn't have to be a problem though...
Re: Bochs output
OK, the divide by zero error makes sense then if it just keeps jumping back to where it was before.
However, I'm still confused about the other error message. You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
Also something I noticed in my bochs output was the all my segments are stored in segments 3&4 (user mode) segments of my GDT, when previously they were in segments 1&2 (system mode). Would this be causing problems as well?
However, I'm still confused about the other error message. You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
Also something I noticed in my bochs output was the all my segments are stored in segments 3&4 (user mode) segments of my GDT, when previously they were in segments 1&2 (system mode). Would this be causing problems as well?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
https://sourceforge.net/projects/hexciting/
-
- Member
- Posts: 153
- Joined: Sun Jan 07, 2007 9:40 am
- Contact:
Re: Bochs output
It depends on the compiler. Use iretd to be safe.You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
Re: Bochs output
The iret is just poping the cs:ip (but as tantrikwizard said:
while the iretd is popping cs:eip
That should be the reason, if not we will need the souce code, to tell you excatly the problem.
KMT dk
)It depends on the compiler...
while the iretd is popping cs:eip
That should be the reason, if not we will need the souce code, to tell you excatly the problem.
KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
-
- Member
- Posts: 116
- Joined: Wed Oct 22, 2008 2:21 am
- Location: Roma,Italy
Re: Bochs output
Congratulation you are a good asm programmerkmtdk wrote:div ax,cl ; diving with 0 error.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Bochs output
In other words, iret=real mode and iretd=pmode.kmtdk wrote:The iret is just poping the cs:ip ... while the iretd is popping cs:eip
Re: Bochs output
No it doesn't. If anything it depends on the assembler, which it doesn't in this case. It's the same as using "mov" instead of "movl".tantrikwizard wrote:It depends on the compiler. Use iretd to be safe.You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
-
- Member
- Posts: 153
- Joined: Sun Jan 07, 2007 9:40 am
- Contact:
Re: Bochs output
Try researching some different compilers. I said this from experience."No it doesn't. If anything it depends on the assembler, which it doesn't in this case. It's the same as using "mov" instead of "movl"."
most 32-bit compilers produce the 32-bit version of this code:
Code: Select all
__declspec(naked)
void ISR0(){
__asm{ iret }
}
samoz stated the program was running in protected mode. I have no reason not to believe him. The output depends on the compiler, use iretd to be safe.
P.S. "movl" is not a valid instruction on most assemblers.