Strange Error in my OS

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
hunter
Posts: 12
Joined: Fri Jan 05, 2007 9:47 am

Strange Error in my OS

Post by hunter »

Hello,

i've a big problem with my operating system ... there is a bootloader which loads two files in the memory : System.sys (Adr.: 0x2400) and Kernel.sys (Adr.: 0x10000)

if the files are loaded the bootloader jump to the system.sys where the video card,gdt,a20,... were loaded ...

the system.sys switch to PM and jump to the kernel (Adr.: 0x10000)

The problem is the kernel size ... if the kernel size is lower than 65536 Bytes all works fine ... but if I add a codeline and the kernel size is upper 65536 Bytes the system (Bochs,Virt.-PC,..) reboots ... VM-Ware shows a "Kernel Stack Fault" Error ... i hope somebody could help me ...

Hunter
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post by urxae »

Presumably, since you only switch to PM once system.sys is loaded, you are loading the files in real mode?
Are you taking the fact that Real Mode segments are only 64 KiB into account?
And do you also take into account that a 16-bit unsigned integer can only hold a maximum value of 65535 (64 Ki - 1)?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Post by bubach »

Did you already check where your stackpointer points to? Could you be overwriting your kernel with the stack or the other way around?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
hunter
Posts: 12
Joined: Fri Jan 05, 2007 9:47 am

Post by hunter »

The Files Kernel.sys and System.sys were loaded from the bootloader ... in bochs debugmode the os jump to 0x10000 (Kernel start) and call the C-Function ... its very strange because if the kernel size is lower 64K the C-Function is called and all works fine ... if the kernel size is over 64K the c_Funktion ( void main() ) isn't executed ...

if i change the stack pointer adress the problem also happens ...

Hunter
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:

Post by Combuster »

have you checked that you aren't experiencing segment overflows?

If you for example INC AX when its 0xffff (65535) it wraps to 0 instead of becoming 65536. if you load your kernel this way, you'll end up overwriting the start of your kernel (where your entry point is located) when it gets larger than 64k. When that happens, the code executed is bogus with the obvious consequences...
"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 ]
m
Member
Member
Posts: 67
Joined: Sat Nov 25, 2006 6:33 am
Location: PRC

Post by m »

Combuster wrote:have you checked that you aren't experiencing segment overflows?

If you for example INC AX when its 0xffff (65535) it wraps to 0 instead of becoming 65536. if you load your kernel this way, you'll end up overwriting the start of your kernel (where your entry point is located) when it gets larger than 64k. When that happens, the code executed is bogus with the obvious consequences...
It's proberbly the point because most BIOS interrupts are 16-bit procedures(suppose you're using INT 0x13).

So if you want to execute procedures larger than 64 kb,you can load their image on the disk in several times(in each of which you load 64 kb or less) first into RAM within the 1st 1 mb,and then jump to PM and copy and combine the loaded parts to the location you want and finally set up a code segment for it to run.
INF1n1t
Member
Member
Posts: 60
Joined: Fri Dec 22, 2006 5:32 pm
Location: Somewhere Down...

Post by INF1n1t »

One segment has the size of 64 KB, right? (we're talking about real mode). So the boot loader code could load the whole file (larger than 64 KB) with no problems. You just have to right code to check for segment overflow (by checking the offset size). When coming near the segment overflow, we can update the segment register ;) That's one of the solutions of the problem, which I think I'm gonna use ;)
I think, I have problems with Bochs. The biggest one: Bochs hates me!
Post Reply