-2

If i'm writing my own kernel I will have access the the physical memory (instead of a virtual memory).

Now assume I want to make a loop starting from the first memory location until the last one and set every byte to 0xFF. My pointer will start like this:

unsigned char *firstMemoryAddress = N;

What would N be? in embedded systems I can refer to the data sheet of the specific microcontroller, but lets' say Im running this on my laptop hardware. will N be a specific value at all times in Intel based machines? How can I find it?

  • Read the datasheet for your processor. – whatsisname Sep 17 '18 at 3:09
  • The compiler doesn't assign the memory address. It assigns an offset. The actual starting address is assigned the moment it's launched. It could even be 0x0. – Neil Sep 17 '18 at 7:32
2

There is no standard way to ask a generic memory subsystem what true/valid memory there is when writing an operating system from scratch that should function across any and all computers.

The approach settled on by IBM-PC types and their clones is that determining this is a BIOS function, not an operating system function.  This BIOS operation is performed early in the boot process and is customized by the board manufacturer for a particular board, and so, has detailed knowledge of the possible locations and potential types of RAM modules vs. I/O devices.

Even within the x86 PC's, attempting to do this by your own custom algorithm will be extremely error prone.  If you expand to include other platforms (phones, devices, etc...) it is probably a hopeless task.  So, the best bet is to rely on the standards and practices that have emerged, such as relying on BIOS functions to tell you.

  • I have followed the osDev.org tutorials and created a simple kernel. Now all I do in it is do int a = 5 and will output it on a vga screen with a custom printf function. now where is a stored? what gave it it's mem address? I'm the OS at this point and haven't done any memory management. – xnight Sep 17 '18 at 3:09
  • If you're going to run some C code, then you pretty much have to have a runtime stack. The a variable will be on that stack. So, where did you allocate that stack? Once you know that, you can start to zero in on where a is within that stack. – Erik Eidt Sep 17 '18 at 3:11
  • Oh i did it in bootstrap assembly: wiki.osdev.org/Bare_Bones under Bootstrap Assembly – xnight Sep 17 '18 at 3:12
  • 1
    @xnight if you look at the "Linking the Kernel" section in the OSDEV page, you'll see linker code directing that kernel to be loaded into memory starting at 1Mb. The bottom of the stack will be above that. How much depends on what data you have in your .text, .rodata, .data, and .bss segments. The bottom of your stack will be at end of the .bss segment, and the top will be 16Kb above that. The details are determined by the directives in your bootstrap assembly and the linker script. – Charles E. Grant Sep 17 '18 at 4:22
  • 1
    @xnight the reason that the answers you are getting are so confusing is that you are framing the questions in an entirely general way, but you are working in a very specific framework. Other operating systems and frameworks may do it differently then OSDEV. – Charles E. Grant Sep 17 '18 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.