Page 1 of 1
[Solved]Unknown Error
Posted: Tue Jul 05, 2011 12:26 am
by melgmry0101b
Hi everyone,
I attempted to load a file that its size is bigger than 64 KB to the memory by loading it in a variable.
I pointed this variable to a point in the memory by malloc.
OK , no problem with it in Virtual PC but if i started doing that in the real hardware the OS restarts automatically.
At first i thought that the problem is in the Floppy Driver, but i didn't find any error in it.
Can anyone help me?
---------------------------------
Thank you in advance.
Re: Unknown Error
Posted: Tue Jul 05, 2011 1:15 am
by xenos
First, you should try to find out where exactly the problem occurs. Put a "cli" and a "hlt" instruction somewhere in your code and see if the computer still resets or if it just hangs.
Have you set up any exception handlers? It is often very helpful if your OS shows a panic screen and a register dump when an exception occurs, instead of just rebooting.
Re: Unknown Error
Posted: Tue Jul 05, 2011 1:21 am
by melgmry0101b
Yes , i sat up any exception handlers
About the "CLI" , "STI" and "HLT" i will try.
Re: Unknown Error
Posted: Tue Jul 05, 2011 3:38 am
by Karlosoft
Are you sure the var you used for the file size isn't 16bit long? Integers in real mode are a word in most of the compilers.
Re: Unknown Error
Posted: Tue Jul 05, 2011 4:40 am
by melgmry0101b
My OS is protected mode and the type of the var is "char"
Re: Unknown Error
Posted: Tue Jul 05, 2011 6:47 am
by DLBuunk
As for using a char as type for a variable, that cannot be the problem, as chars are stored as 32-bit variables in the non-array case, as putting a single char on the stack would wreck the alignment. (besides, the OP probably meant char * , i guess).
It is still very bad to use char for anything larger that 8 bits.
A floppy disk crash after 64 KiB that isn't there on an emulator sure smells like DMA troubles to me.
Re: Unknown Error
Posted: Tue Jul 05, 2011 10:58 am
by melgmry0101b
I am writing my OS in C language and i am using "char*" for the var
My DMA points to 0x1200
This error is too strange because i cant get any error code or to debug the kernel because i am in real hardware?
Re: Unknown Error
Posted: Tue Jul 05, 2011 11:08 am
by melgmry0101b
And about the DMA
I didn't found any error in it because i read that file again but with printing the contents on the screen , the OS ran normally with no errors.
Re: Unknown Error
Posted: Tue Jul 05, 2011 12:34 pm
by DavidCooper
You replied to:-
XenOS wrote:First, you should try to find out where exactly the problem occurs. Put a "cli" and a "hlt" instruction somewhere in your code and see if the computer still resets or if it just hangs.
with:-
Mozo40 wrote:About the "CLI" , "STI" and "HLT" i will try.
I hope you try it without the STI.
DLBluunk provided a likely clue:-
DLBuunk wrote:A floppy disk crash after 64 KiB that isn't there on an emulator sure smells like DMA troubles to me.
I've never used the DMA (because I used to load with DMA and interrupts off, and now I use the BIOS instead so that I can load from USB floppy), but I have read something about it having a 64KB limit on transfers. Are you trying to load this file in such a way that it's hitting its limit?
This error is too strange because i cant get any error code or to debug the kernel because i am in real hardware?
I always work in real hardware - the trick is to find ways of getting the right information out when things go wrong. Send information to the screen periodically to monitor what's going on and to narrow down the point where things go wrong.
Mozo40 wrote:And about the DMA
I didn't found any error in it because i read that file again but with printing the contents on the screen , the OS ran normally with no errors.
Does that mean you can load it in if you're doing it to print the contents to the screen, but that it goes wrong if you try to load it in to do something else with it? If so, that suggests it may be going wrong after loading successfully, so you need to try the cli hlt thing at the right point to find that out.
Going back to your original post:-
Mozo40 wrote:I attempted to load a file that its size is bigger than 64 KB to the memory by loading it in a variable.
I pointed this variable to a point in the memory by malloc.
If the file is loading properly, are you sure malloc is giving it as much space as it needs and that it isn't overwriting something vital? I don't know how malloc works, but maybe you need to post some of your code so that someone else can check that, though make sure it isn't a loading problem first (by using cli and hlt immediately after the attempt to load it).
Re: Unknown Error
Posted: Wed Jul 06, 2011 1:30 am
by melgmry0101b
About the "CLI" , "HLT" and "STI" , i tried it but i didn't get any solutions.
DavidCooper wrote:I've never used the DMA (because I used to load with DMA and interrupts off, and now I use the BIOS instead so that I can load from USB floppy), but I have read something about it having a 64KB limit on transfers. Are you trying to load this file in such a way that it's hitting its limit?
I am in protected mode and i don't have vm86 to use the Bios.
about the limit i read sector by sector each time , not all sectors in one time.
DavidCooper wrote:If the file is loading properly, are you sure malloc is giving it as much space as it needs and that it isn't overwriting something vital?
I checked it before and it gives me enough space.
Re: Unknown Error
Posted: Wed Jul 06, 2011 5:12 am
by AJ
Hi,
I don't see this going anywhere other than around in circles.
@op: As suggested, you need to debug your code. It also sounds like you are making assumptions (or not providing details) about the fact that malloc is working and the FDD driver is working. Are you sure that the FDD driver is playing nicely with your memory allocation routine?
One other thing to check - often when there's a problem with a hardware driver on a real PC but not on a virtual machine, it's to do with timings (look at your port IO). Have you taken in to account the fact that you have to wait for real hardware?
Cheers,
Adam
Re: Unknown Error
Posted: Wed Jul 06, 2011 11:33 am
by DavidCooper
Mozo40 wrote:About the "CLI" , "HLT" and "STI" , i tried it but i didn't get any solutions.
If you put cli and hlt into your code immediately after the file has loaded you will find out something vital. If it tripple faults the machine, the fault lies before that point and it's something to do with the way the file's being loaded. If it just hangs, the fault is further on. If it's doing both of those things at the same time, then you've entered some weird quantum state which would excite the likes of Hawking. I don't believe that can have happened - if you do the cli hlt thing properly, you will normally get a useful answer. If you're having difficulty putting it into your code, try putting a conditional jump in front of the cli hlt so that you can activate it at a very specific time just by changing a variable.
DavidCooper wrote:I've never used the DMA (because I used to load with DMA and interrupts off, and now I use the BIOS instead so that I can load from USB floppy), but I have read something about it having a 64KB limit on transfers. Are you trying to load this file in such a way that it's hitting its limit?
I am in protected mode and i don't have vm86 to use the Bios.
about the limit i read sector by sector each time , not all sectors in one time.
I was just explaining my lack of knowledge of how the DMA works, but it occurred to me that you might not be resetting it in the right way to ensure that it doesn't hit its 64KB limit by the time it reaches the last part of your >64KB file. If you've checked that properly and it isn't the case, then that's fine, but your first step is still to find out if the tripple fault is caused before the file has finished loading or afterwards - until you do that you're not going to be sure you're looking in the right place to find the error, and the hardest bugs often need to be pinned down to the point where you know for certain that you must be looking right at them even though you still can't see the fault.
Re: Unknown Error
Posted: Wed Jul 06, 2011 3:51 pm
by melgmry0101b
Thank you for all replies,
I have repaired the problem , It was an error in the floppy not in the memory or the var.
Thank you again.