reading memory size

How do I read the size of installed memory?
Do I use BIOS interrupt?
If so I im also interested how bios is doing this.
Perhaps by writeing and reading io mapped north bridge registers.
How is memory detected when the pc is started?

Do you have any links,tutorials about this?
Many thanks.

Comments

  • : How do I read the size of installed memory?
    : Do I use BIOS interrupt?
    : If so I im also interested how bios is doing this.
    : Perhaps by writeing and reading io mapped north bridge registers.
    : How is memory detected when the pc is started?
    :
    : Do you have any links,tutorials about this?
    : Many thanks.
    :

    How you do this would depend on the system you're running. Using Linux (and possibly other *nix systems, but I'm not sure), you'd parse the contents of /proc/meminfo.

    What Operating System and compiler are you using?
    Sincerely,
    Jakykong (Jack Mudge)
    [email protected]
  • Maybe DOS but I am playing with the idea to
    write something simple that boots and runs
    without OS. So I am interested in how the
    BIOS/OS is doing this.

    Also I should maybe post this in the assembler message board
    but I am plannig to use C/C++.


  • ---

    If you are wanting to do this without an existing OS or system software, and have an x86 compatible machine:

    There are several methods. The Bios itself is limited to the low 1 MB of memory though as it is running in real mode. There are several methods to detect all of memory; including probing memory (Not recommended)

    Most modern systems use several methods to determine this and run in pmode. In any case, it can only be done in ring 0 which is why normal programs cannot do it directly.

    This can only be used in real mode or v86 mode at ring 0:
    [link=http://www.ctyme.com/intr/rb-0598.htm]Bios int 0x12[/link].

    As the above link shows, you can also just read the word at 0040h:0013h.

    It can be done in C and C++ as long as you are running in ring 0.

    ---

    If you want to do this in a standard ring 3 program, you will be required to go through the system API.

    ---
    Im surprised this is posted in the beginner C++ forum...

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
  • Thanks, this helps.

    I am sort of a beginner in C/C++ and programing
    but now I am shure I made a mistake posting this here.
    Sorry.

  • I did this in borlandc(dos):

    #include

    unsigned far *memsize =(unsigned far*) 0x00400013;

    void main(){
    printf("
    mem size is: %d ",*memsize);
    }

    and the output is:
    mem size is: 640

    in DOS and in DOS window.

    So this only gives me the size of conventional memory in KB.
    As I read in a help file of borlandc program bios call does the same.
    But when I type mem at dos command prompt i get all sorts of info on
    memory.So how is this program doing this or do I have to
    disassemble it? (and I never done this before)

    I am going to have to learn about this ring thing but I am guessing
    its a mode of the processor when it has all the priviledges
    and that its only for 386+ processors.
  • : I did this in borlandc(dos):
    :
    : #include
    :
    : unsigned far *memsize =(unsigned far*) 0x00400013;
    :
    : void main(){
    : printf("
    mem size is: %d ",*memsize);
    : }
    :
    : and the output is:
    : mem size is: 640
    :
    : in DOS and in DOS window.

    When working without an existing OS, the above will not work.

    : So this only gives me the size of conventional memory in KB.
    : As I read in a help file of borlandc program bios call does the same.

    It does. ...Kind of.

    Windows emulates an 8086 envirement through v86 mode. When the Bios int is called, Windows emulates it.

    : But when I type mem at dos command prompt i get all sorts of info on
    : memory.So how is this program doing this or do I have to
    : disassemble it? (and I never done this before)

    It gets the information from the system API or through system interrupts.

    : I am going to have to learn about this ring thing but I am guessing
    : its a mode of the processor when it has all the priviledges
    : and that its only for 386+ processors.

    Yep. Any time a privledge instruction is executed, the processor switch protection levels (This is what rings are)

    : Thanks, this helps.

    : I am sort of a beginner in C/C++ and programing
    : but now I am shure I made a mistake posting this here.
    : Sorry.

    Dont be sorry :) I am to admit that low level programming in any language can be a challenge, which is why I do not recommend it for beginners. If its only for experience or fun, why not?

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories