IDT Problem when the binary is of more than 80 KB

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
spderosso
Posts: 4
Joined: Wed Oct 28, 2009 8:34 am

IDT Problem when the binary is of more than 80 KB

Post by spderosso »

Hello!
I have the following problem, my os worked more or less ok up to the moment when the binary of my os became bigger than 80 KB. Now, i can't even do like "int 80h" because it generates a "jump far" even though i am able to access the handler function "call _int_80_hand" directly when not going through the interrupt table. Suppose that the code is ok, could these be a linking or compiling issue? what could be happening?

Thank you very much!
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: IDT Problem when the binary is of more than 80 KB

Post by NickJohnson »

I'm guessing your problem is that the actual loadable size of the kernel has exceeded 64 KB, which may make some primitive bootloaders choke. What bootloader are you using? Other general information would probably be useful too.
spderosso
Posts: 4
Joined: Wed Oct 28, 2009 8:34 am

Re: IDT Problem when the binary is of more than 80 KB

Post by spderosso »

NickJohnson wrote:I'm guessing your problem is that the actual loadable size of the kernel has exceeded 64 KB, which may make some primitive bootloaders choke. What bootloader are you using? Other general information would probably be useful too.
Thanks for the quick answer!
This is the situation: i'm using grub 0.96 and the link.ld i'm using is the following:

Code: Select all

ENTRY (_loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }
}
The problem occurs when the binary exceeds 80K.

Thanks very much!
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: IDT Problem when the binary is of more than 80 KB

Post by Combuster »

Since you are using GRUB and ld, the chance that the toolchain is involved in the error is virtually absent.

Have you tried running your code in bochs? What are the error messages there (if any)?
"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 ]
spderosso
Posts: 4
Joined: Wed Oct 28, 2009 8:34 am

Re: IDT Problem when the binary is of more than 80 KB

Post by spderosso »

Combuster wrote:Since you are using GRUB and ld, the chance that the toolchain is involved in the error is virtually absent.

Have you tried running your code in bochs? What are the error messages there (if any)?
I'm using bochs, the error is number 13 and goes something like "Invalid Executable format" though the format seems to be ok. I've been trying out some stuff and if i compile it in a different order it works but is not possible to do "int XXh".

Thank you!
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: IDT Problem when the binary is of more than 80 KB

Post by Combuster »

For the first problem, read the FAQ.

For the second problem, please read my previous post again: what does bochs say (= what does the log show)
"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 ]
spderosso
Posts: 4
Joined: Wed Oct 28, 2009 8:34 am

Re: IDT Problem when the binary is of more than 80 KB

Post by spderosso »

I found the problem..thank you very much!

The idtr loading-code had a bug. The problem was the way the function recovered the parameter from the stack:

Code: Select all

_lidt:				; loads IDTR
        push    ebp
        mov     ebp, esp
        push    ebx
        mov     ebx, [ss: ebp + 6] ; HERE IS THE BUG!! it should be ebp + 8 and the rol shouldn't go
	rol	ebx,16		    	; 
	lidt    [ds: ebx]          ; loads IDTR
        pop     ebx
        pop     ebp
        retn
The call to the function was something like this:

Code: Select all

	/* loads the IDTR */
	idtr.base = 0;  
	idtr.base +=(dword) &idt;
	idtr.limit = sizeof(idt)-1;
	
	_lidt (&idtr);	
So, when the code was small the high part of ebp+6 was the same as the high part of ebp +8 then no problem occurred. But when the code got bigger this was not the same and that was the reason why when the binary got bigger than 80 K the problem appeared.

Thank you all!
Post Reply