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.
hello, everyone.
i find a strange thing, i write a function in my kernel to scan RAM from 32M ~ 896M, four bytes one step. i want see how many dirty machine words( not zero) exist after power on.
A more interesting experiment would be to run an image recognizer on that memory! All kinds of recognizers, actually. People have been finding Christ in bread toasts and tree stumps. Who knows what you may find in there! Perhaps, you may find a proof of an important mathematical conjecture or a beautiful painting or a touching symphony!
Seriously, why would you care? Depending on how long the machine was off and on what the BIOS did to the memory, you may find in there data from a previously run OS. Or you may probably use the content to initialize your random generator (provided, there's enough entropy, I guess). Other than that, the data is probably as good as junk (I'm not sure if it can reveal anything useful about its own organization and operation).
In the early period of my wring the kernel, i assume the machine ram is clean beyond 1M. For a long time, my kernel runs will on virtual machine, but cracked when i test it on my home PC these days.
I found out the reason, so ...
I've heard something about memory scrubbing by the BIOS/chipset on some machines, but that's not all machines and I'm not sure there's any guarantee as to the memory state (scrubbing with random numbers or with zeroes or with some pattern) when the BIOS hands off control to the OS. In any case, you shouldn't expect anything. Unless, of course, you're in full control of the hardware.
Make no assumptions except what is specified.
By instance , if your kernel is ELF, the memory where your .bss segment is, is cleared.
Always assume the worst, like the multiboot header being right after your kernel in memory.
You should clear whatever you take from your physical allocator for security AND safety.
alexfru wrote:A more interesting experiment would be to run an image recognizer on that memory! All kinds of recognizers, actually. People have been finding Christ in bread toasts and tree stumps. Who knows what you may find in there! Perhaps, you may find a proof of an important mathematical conjecture or a beautiful painting or a touching symphony!
Or more likely, fragments of partially-intact data from previous use. Whether or not you find a beautiful painting in there or not depends on whether or not the previous user of the system looked at any beautiful paintings (and likewise with touching symphonies).
In reality, as long as the charge in the DRAM chips has dissipated (which it almost certainly has), you'll probably find just white noise. Statistically, the distribution of bits in memory that has been "initialised" by electromagnetic noise while the system is turned off is even, resulting in white noise (or whatever the graphical equivalent of that is, depending on how you interpret the data).
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Boris wrote:Preserve those dirty bytes and use them as a funny hardware random numbers generator.
Please don't. Just, don't.
"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 ]
In the early period of my wring the kernel, i assume the machine ram is clean beyond 1M. For a long time, my kernel runs will on virtual machine, but cracked when i test it on my home PC these days.
I found out the reason, so ...
This is why you should always initialize your variables and clear any buffers you allocate before use.
<PixelToast> but i cant mouse
Porting is good if you want to port, not if you want maximum quality. -- sortie
Also, if you are ever planning on dynamically allocating memory (malloc()), or if you are ever planning on enabling hardware paging, you are going to have to deal with "dirty" memory, one way or another.
Either the OS should clear any memory that it allocates, or all of your applications should expect any (non-code) memory to be filled with garbage.
Speaking of garbage, I'm not sure if I mentioned it on here before, but while I was testing out my memory stream reader, dumping the individual bytes to the screen, I found some text in the BIOS area of my physical laptop that said something along the lines of "This code is for non-production use only."
Hehe. Whoops.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott