Page 1 of 1
Strange Error in my OS
Posted: Sat Jan 06, 2007 1:22 pm
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
Posted: Sat Jan 06, 2007 1:47 pm
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)?
Posted: Sat Jan 06, 2007 1:47 pm
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?
Posted: Sat Jan 06, 2007 2:04 pm
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
Posted: Sat Jan 06, 2007 2:11 pm
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...
Posted: Sat Jan 06, 2007 10:45 pm
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 part
s to the location you want and finally set up a code segment for it to run.
Posted: Sun Jan 07, 2007 3:34 pm
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