flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Protected Mode Memory

Author
Thread Post new topic Reply to topic
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
I have a function that reads a byte from memory at every 1MB interval and stores the number of times this successfully happens, upon error, that value indicates the total megabytes of RAM on the system. This works fine on my DDR machines (P4, Athlon64, Celeron M), but on an older SDRAM machine (AMD K6-III) it returns nothing. Any ideas as to why, and/or how to fix this?
Post 05 Mar 2007, 05:07
View user's profile Send private message Reply with quote
tantrikwizard



Joined: 13 Dec 2006
Posts: 142
tantrikwizard
Not sure why this is happening. What is the purpose of the code? Is there another way to work the algorithm?
Post 05 Mar 2007, 11:28
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
I have figured out that the function does work - there was an error in my printing function which is fixed..... The problem now is the huge output. It will return 100000000h - 24 which just happens to be the beginning of the algorithm I'm using (1MB intervals, at the end subtract 24). I can't tell why the code will loop this many times. Would it be easier if I pasted the code here?
Post 05 Mar 2007, 12:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yes, paste the code please Smile
Post 05 Mar 2007, 12:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
I just tried this on my Athlon64 2800 and it gave the bogus value, so my two AMD boxes report bogus sizes, and my single Intel box reports the correct amount of RAM.... dunno if that has anything to do with it.


The GDT entry is 4GB limit, R/W. If there is any other known way to determine the total amount of physical RAM in protected mode, it would be much appreciated if that function was shared.

Code:

RAM_Size:
        mov eax,10h
        mov ds,eax
        mov es,eax
        mov eax,1000000
        mov edi,eax
        mov esi,eax
        xor ecx,ecx
        mov eax,0AAh
rep_mem:
        stosb
        lodsb
        cmp eax,0AAh
        jne set_var
        inc ecx
        add esi,999998
        add edi,999998
        jmp rep_mem
set_var:
        lea edi,[mbram]
        mov eax,ecx
        sub eax,24
        stosd
    
Post 05 Mar 2007, 18:20
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Code:
mov eax,1000000
    

Code:
add esi,999998 
    


Where do these values come from ??? Question

How many bytes has one MB ? Question

Quote:
at the end subtract 24


Why ? Question

Code:
lea edi,[mbram]
mov eax,ecx
sub eax,24
stosd
    


There might be simpler ways to do ...

Finally, you would have to save and compare at least 2 different
values to get sure that RAM exists at that address ...

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 05 Mar 2007, 20:52
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
1.000.000 in decimal is F4240 in hex, which, if the base of your descriptors is 0, is a ROM address and might confuse your algorithm.
Post 05 Mar 2007, 21:11
View user's profile Send private message Visit poster's website Reply with quote
tantrikwizard



Joined: 13 Dec 2006
Posts: 142
tantrikwizard
Navic wrote:
If there is any other known way to determine the total amount of physical RAM in protected mode, it would be much appreciated if that function was shared.
Setup paging and when a page is requested that is out of bounds you will get a page fault. This can be setup in a loop, expanding the limit of a GDT entry until the exception occures.
Post 05 Mar 2007, 21:26
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
ROM address and might confuse your algorithm


Right ... will return 0 !!! Start testing at $180000 (1.5 MB) and jump in
$80000 (512 KB) steps ... and reject result if it is $180000
(would mean less than 2 MB RAM or algo failure) Idea

And, still, test 2 values per address ...

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 05 Mar 2007, 21:48
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
You shouldn't do memory detection this way... ROM, memory mapped devices, etc. Query the BIOS instead, e820.
Post 05 Mar 2007, 23:39
View user's profile Send private message Visit poster's website Reply with quote
tantrikwizard



Joined: 13 Dec 2006
Posts: 142
tantrikwizard
f0dder wrote:
You shouldn't do memory detection this way... ROM, memory mapped devices, etc. Query the BIOS instead, e820.
Agreed, but any way to perform same through PMode without BIOS? Can't one query the PCI BUS for same reserved addess spaces?
Post 06 Mar 2007, 05:48
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
Taking into account most systems that are around today have large amounts of RAM, would testing every 32MBs work? I understand there are I/O, PCI, ROM, etc spaces, but I was hoping to find a test value that would either skip these spaces..... not very probable I guess? My values were based on 1000000 starting, and since I used 0AAh to test, an increment should be 1000000-2 correct?
Post 06 Mar 2007, 07:10
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
tantrikwizard wrote:
f0dder wrote:
You shouldn't do memory detection this way... ROM, memory mapped devices, etc. Query the BIOS instead, e820.
Agreed, but any way to perform same through PMode without BIOS? Can't one query the PCI BUS for same reserved addess spaces?

Afaik, PCI management is done through BIOS calls? (perhaps only to get a 32bit callable entrypoint - haven't done PCI setup myself). You can either query the e820 memory map before entering pmode, or you can use v86 to thunk down.

Navic: better be safe and do it the e820 way, and falling back to older mechanisms in case bios doesn't support e820. There's a few broken BIOSes that don't support e820 correctly, but IMHO those should just be ignored, unless you want to end up with a bloated "support everything and have no specific goals" kernel.

_________________
Image - carpe noctem
Post 06 Mar 2007, 10:16
View user's profile Send private message Visit poster's website Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
Well this question will show how much of a newbie I am...... what is the e820 map?
Post 06 Mar 2007, 17:37
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Post 06 Mar 2007, 22:28
View user's profile Send private message Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic
I've found a good algorithm for physical memory detection:
Code:
;By Jeff Leyda
        xor edx,edx             ;MB counter
        mov eax,0cafef00dh ;test data
        mov edi,100000       ;start
testLoop:
        mov ebx, [edi]       ; save current memory contents
        mov [edi], eax       ; write memory 
        cmp [edi], eax       ; did it stick?
        jnz endoftest
        mov [edi], ebx       ; restore memory
        add edi, 1024*1024   ; next mb
        inc edx              ; update counter
        jmp testLoop
endoftest:
        lea edi,[mbram]
        mov eax,edx
        stosw
    


This works on all my systems.
Post 07 Mar 2007, 17:59
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Again: don't do it this way. Please, think of the kittens!
Post 07 Mar 2007, 23:13
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
kittens .... Confused
The E820 BIOS method is a real mode solution.
If this were a purely protected mode task, then how will E820 be useful?
Embarassed
Post 08 Mar 2007, 09:02
View user's profile Send private message Reply with quote
ilya



Joined: 29 Apr 2007
Posts: 2
ilya
I think it possible to go over all PCI devices and get the BARs largest address + range will be equal to min RAM available.
Post 07 May 2007, 13:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.