[Solved]Unknown Error

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
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

[Solved]Unknown Error

Post 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.
Last edited by melgmry0101b on Thu Jul 07, 2011 4:13 am, edited 1 time in total.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Unknown Error

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

Post by melgmry0101b »

Yes , i sat up any exception handlers
About the "CLI" , "STI" and "HLT" i will try.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Unknown Error

Post 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.
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

Post by melgmry0101b »

My OS is protected mode and the type of the var is "char"
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: Unknown Error

Post 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.
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

Post 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?
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

Post 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.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Unknown Error

Post 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).
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Unknown Error

Post 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
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Unknown Error

Post 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.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Unknown Error

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