flat assembler
Message board for the users of flat assembler.

Index > DOS > AMDECHO: New kinda ECHO command replacement ;)

Author
Thread Post new topic Reply to topic
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
I just started yesterday (24.05.2005) writing a small native DOS onyl COM tool that takes the commandline string, writes it to the AMD Athlon model 2 or above brand string MSRs, retrieves this string via CPUID and echoes them back to the console. All this just for fun!!! Cool

It actually appears to work like the original ECHO command, just with the exception that the string is taken through the CPU brand name.

I's not finished, e.g. I just started it!
- It requires an AMD Athlon model 2 or newer CPU to work


have fun!

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||


Last edited by MCD on 26 Dec 2006, 10:21; edited 3 times in total
Post 25 May 2005, 11:24
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
More complete version of AMDECHO. Please post any suggestions/bugs.

-AMDECHO with proper CPU and protected mode detection.
-Fixed the bug which caused the retrieved string to be cut off at 32 instead
of 48 characters.
-Some basic user strings were added (usage...)
Code:
nl      equ 0Dh,0Ah

org     100h

Start:
        mov     ah,70h          ;check for 80386+ CPU
        push    ax
        popf                    ;BTW this clears direction and interrupt flags
        pushf
        pop     bx
        cmp     bh,ah
        jne     ErrNoAMDAthlon

        pushfd                  ;check for CPUID instruction
        pop     eax
        bts     eax,21
        push    eax
        popfd
        pushfd
        pop     ebx
        cmp     ebx,eax
        jne     ErrNoAMDAthlon

        xor     eax,eax
        cpuid
        or      eax,eax         ;CPUID page 0 and 1 supported?
        jz      ErrNoAMDAthlon
        cmp     ebx,"Auth"      ;Allow only AMD CPUs Mad
        jne     ErrNoAMDAthlon  ;does this work on other CPUs? I have no clue
        cmp     edx,"enti"
        jne     ErrNoAMDAthlon
        cmp     ecx,"cAMD"
        jne     ErrNoAMDAthlon
        mov     eax,1
        cpuid
        cmp     ax,620h         ;Athlon (Family 6) and Model 2 required
        jb      ErrNoAMDAthlon

        smsw    ax              ;check whether CPU is in protected mode
        test    al,1
        jz      RealModeOk
        call    ExitMsg
        db      "error: CPU in protected mode.$",nl

ErrNoAMDAthlon:
        call    ExitMsg
        db      "error: AMD Athlon(tm) model 2 CPU or newer required.$",nl

RealModeOk:
        mov     si,81h
        mov     cx,7Fh
FindCmdlnStart:
        lodsb                   ;skip first spaces
        cmp     al," "
        loope   FindCmdlnStart
        dec     si

        mov     cx,48
        mov     bx,si
ScanCmdln:
        lodsb
        or      al,al
        jz      CmdlnEnd
        cmp     al,0Dh          ;replace character 0Dh with 0
        je      StripTrailChr
        loop    ScanCmdln
        jmp     CmdlnEnd
StripTrailChr:
        mov     [si-1],ch       ;ch contains 0

CmdlnEnd:
        dec     si
        cmp     si,bx
        jne     CmdlnOk
        call    ExitMsg
        db      "usage: AMDECHO [string]",nl,nl,\
                "Writes string into the CPU brand string MSRs, retrieves and echoes it.",nl,\
                "String is limited to 47 characters.$",nl

CmdlnOk:
        inc     si
ClrCmdln:
        mov     [si],ch
        inc     si
        loop    ClrCmdln        ;pad the rest with zeros until offset +48

        std                     ;MSR writing is done in reverse
        lea     si,[bx+48-4]
        mov     ecx,0C0010035h  ;magic MSRs
WriteMSR:
        lodsd
        mov     edx,eax
        lodsd
        wrmsr
        cmp     cl,30h
        loopne  WriteMSR

        sti
        mov     eax,80000002h   ;now retrieve written string
        mov     di,81h          ;use commandline as buffer, just overwrite it
GetCPUStr:
        push    eax
        cpuid
        mov     [di],eax
        mov     [di+4],ebx
        mov     [di+8],ecx
        mov     [di+0Ch],edx
        pop     eax
        inc     al
        add     di,10h
        cmp     al,5
        jne     GetCPUStr

        mov     byte [di-1],"$"
        push    81h
ExitMsg:
        mov     ah,9            ;display exit message
        pop     dx
        int     21h
        int     20h
    

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 27 May 2005, 09:14
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. Also on YouTube, Twitter.

Website powered by rwasa.