Bochs output

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
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Bochs output

Post by samoz »

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?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Bochs output

Post by Love4Boobies »

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 ]
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: Bochs output

Post by kmtdk »

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:

Code: Select all

xor cx,cx
mov ax,0x0001

div ax,cl ; diving with 0 error.
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
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.
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Re: Bochs output

Post by hailstorm »

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...
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Re: Bochs output

Post by samoz »

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?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: Bochs output

Post by tantrikwizard »

You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
It depends on the compiler. Use iretd to be safe.
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: Bochs output

Post by kmtdk »

The iret is just poping the cs:ip (but as tantrikwizard said:
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.
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: Bochs output

Post by djmauretto »

kmtdk wrote:div ax,cl ; diving with 0 error.
Congratulation you are a good asm programmer :wink:
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Bochs output

Post by Troy Martin »

kmtdk wrote:The iret is just poping the cs:ip ... while the iretd is popping cs:eip
In other words, iret=real mode and iretd=pmode.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Bochs output

Post by JamesM »

tantrikwizard wrote:
You mentioned using the iretd command, but I'm following James M's tutorials, which uses the iret command. Could this be causing problems?
It depends on the compiler. Use iretd to be safe.
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
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: Bochs output

Post by tantrikwizard »

"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"."
Try researching some different compilers. I said this from experience.

most 32-bit compilers produce the 32-bit version of this code:

Code: Select all

__declspec(naked)
void ISR0(){
    __asm{ iret }
}
However, Open Watcom's WCL386 does not even though it's a 32-bit compiler. If this code appears in a module with other code, every piece of that module will compile to 32-bit except for this ISR0()'s iret statement. It produced the the 16 version (cs:ip) and adds the instruction size prefix to the opcode (0x66) even though everything is compiled for 32-bit code. You must specify iretd to get the 32-bit version. You are partially right in that it can depend on assembler, not only the assembler but also the type of code segment. In a 16-bit code segement iret will normally produce the 16 bit version (cs:ip). The same assembler will often produce the 32-bit version using the same iret instruction if it appears in a code32 segment so it's unclear which is being produced.

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.
Post Reply