flat assembler
Message board for the users of flat assembler.

Index > OS Construction > cpu speed, memory, and keyboard

Author
Thread Post new topic Reply to topic
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed 19 Mar 2005, 05:39
1. How do I get the cpu speed?
2. How do I (safely) get the amount of memory installed?
3. Why does this code triplefault my pc and not bochs:
Code:
format coff
include 'cdecl.inc'

section '.text' code

public _get_scan_key
cproc _get_scan_key
    in al, 0x60
    and eax, 0xFF
    return
endp    

It works fine in bochs, but then again bochs isn't a real pc...
My test pc is a K6-2.

Thanks for any help.
Post 19 Mar 2005, 05:39
View user's profile Send private message Visit poster's website Reply with quote
odrene.koleno



Joined: 14 Feb 2005
Posts: 6
Location: Czech Republic
odrene.koleno 23 Mar 2005, 09:18
Hi,
about the ram... try this thing

Code:
getamountofram:
        push    ebx ecx edi
        ;nastavi nejvyssi bit edi a ecx na 1
        mov     edi,80000000h
        mov     ecx,edi

    ;zacatak cyklu
    .znovu:
        ;kdyz se testuje 10. bit skonci, skok na konec
        ;(snad je kazda ramka v PC vetsi nez 1024 bajtu)
        cmp     ecx,400h
        jz      .konec

        ;vlastni testovani adresy
        mov     ebx,[edi-4]
        mov     dword [edi-4],10101010101010101010101010101010b
        mov     eax,[edi-4]
        mov     [edi-4],ebx
        ;snizeni bitu
        shr     ecx,1

        ;zjistovani jestli test adresy skoncil spravne
        cmp     eax,10101010101010101010101010101010b
        jnz     .nic
        ;jestli jo, zkusi se vice ramky
        add     edi,ecx
        jmp     .znovu
    .nic:
        ;jestli ne, prekvapive se zkusi mene ramky
        sub     edi,ecx
        jmp     .znovu

    .konec:
        sub     edi,400h
        mov     dword [ramsize],edi

        pop     edi ecx ebx
        ret

;sem se uklada velikost ramky
ramsize                 dd 0
     


Sorry for text in comments its in czech language. if you dont understant the code, say it to me and I can provide more explanation.
And two more things. You should execute this code in pmode but before you turn on paging. And also you should have in DS rw selector which covers 0B to 4GB ram.
Post 23 Mar 2005, 09:18
View user's profile Send private message ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 23 Mar 2005, 10:27
odrene, scanning for memory like that is NOT safe - consider things like memory mapped hardware. The way to do it is to use BIOS calls to get the memory map before going to pmode; first you should try the 0xE820 memory map call. If that fails, try 0xE801 which returns a 32bit memory size, and if that fails, finally try 0x88 which is limited to 64meg max.

consumed, are you sure it's this particular code that is causing the triple fault? Or perhaps it's because there's some interrupt happening on your real machine that you haven't set up a handler for? (try masking out interrupts + doing a CLI).
Post 23 Mar 2005, 10:27
View user's profile Send private message Visit poster's website Reply with quote
odrene.koleno



Joined: 14 Feb 2005
Posts: 6
Location: Czech Republic
odrene.koleno 23 Mar 2005, 11:28
f0dder:
OK, you're right. But I thing that (maybe) all memory mapped hardware use lower part of ram below 1MB so I can limit scan from 1MB to 4GB. Just change

"cmp ecx,400h" to "cmp ecx,100000h"

at the begining of function.

One more amount of memory test. Size of ram can be determinated via cmos:
Code:
macro hw.cmos.nactiBajt
{
        out     70h,al
        jmp     $+2
        jmp     $+2
        jmp     $+2
        in      al,71h
}

hw.ram.zjistiVelikost.cmos:
        push    ebx
        xor     eax,eax

        ;nacteni zakladni pameti z cmos v kB
        mov     al,16h
        hw.cmos.nactiBajt
        mov     ah,al
        mov     al,15h
        hw.cmos.nactiBajt

        cmp     eax,280h
        jnz     .konec

        ;nacteni rozsirene pameti z cmos zase v kB
        mov     al,18h
        hw.cmos.nactiBajt
        mov     ah,al
        mov     al,17h
        hw.cmos.nactiBajt

        ;pridani 1MB k rozsirene pameti
        add     eax,400h

    .konec:
        ;z kilobajtu na bajty
        mov     ebx,400h
        mul     ebx
        mov     dword [ramsize],eax
        pop     ebx
        ret

ramsize dd 0
    

But it's limited to 64MB
Post 23 Mar 2005, 11:28
View user's profile Send private message ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 24 Mar 2005, 15:41
Quote:

But I thing that (maybe) all memory mapped hardware use lower part of ram below 1MB

Nope, most hardware in fact uses very high adresses, in the gigabyte range. I must confess that I'm not sure whether the memory mapped ranges are activated by default, or if it requires PCI initialization - but I certainly wouldn't detect available memory with a scan like that, when there's BIOS functions that work well Smile
Post 24 Mar 2005, 15:41
View user's profile Send private message Visit poster's website Reply with quote
DennisCGc



Joined: 03 May 2004
Posts: 24
Location: Zoetermeer, The Netherlands
DennisCGc 26 Mar 2005, 20:56
Post 26 Mar 2005, 20:56
View user's profile Send private message MSN Messenger Reply with quote
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed 27 Mar 2005, 00:22
Thanks for the help. I knew about the BIOS interrupts, but the bootloader I use (bootf02 @ osdever.net) sets up pmode before it jumps to my kernel, which is why I was looking for a pmode-savvy way of doing it. I suppose I'll write my own bootcode now. Smile On a note, I don't think it's the port that's doing it, because I've tried some other code that uses ports (e.g. remapping the PIC) and it triple's my pc too. Confused DennisCGc: I'm having a bit of a hard time understanding how to use that code (possibly 'cause I'm not that good at asm...). Could you provide me a complete example of how to use it? Thanks. Smile
Post 27 Mar 2005, 00:22
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.