flat assembler
Message board for the users of flat assembler.

Index > DOS > Starting devel for DOS with FASM (DPMI32)

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
> Any ideas what is wrong ?

Yes, since it happens in ring0 code, it almost certainly happens during int 21h, ah=3Fh.

Possibly a good opportunity to use the new FD DebugX Wink

Most likely the address returned by DPMI int 31h, ax=0501h, which is a linear address, cannot be used directly for int 21h, ah=3Fh ... it needs some adjustment.
Post 19 Dec 2006, 22:24
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
Possibly a good opportunity to use the new FD DebugX


Found out without. BUT: Found out what is wrong,
but NOT HOW to fix.

File exists and empty: "ordinary" exception "E"
File exists and >=1 bytes: exception "E" in Ring0

OK, let's test single byte writing without any INT: Failure !!! exception "E"

Reading from this segment at least ?: Failure !!! exception "E"

Seems that none of the INT's $31 returns flag(C) set ... Sad everything
seems OK but is crappy: my new great segment is neither writable
nor readable ... it is useless Sad


Code:
segment seg1 use32

              mov    ah,9
              mov    edx,t1
              int 21h
              jmp short @f

t1 db 'Hey ... not yet hello ... trying to allocate INT 31,501 !',0Dh,0Ah,24h

@@:           mov bx,40h          ;BX is high
              mov cx,0            ;CX is low 4MB
              mov ax,0501h 
              int 31h      ;BX:CX = linear address of allocated memory block
              jnc @f       ;OK

              mov    ax,0900h
              mov    edx,t2
              int 21h
              jmp failure

t2 db 'INT 31,501 ran in a failure !!!',0Dh,0Ah,24h

@@:           and EBX,$FFFF
              shl ebx,16
              and ecx,$FFFF
              or ebx,ecx
              push ebx
              mov    ax,$0900
              mov    edx,t3
              int 21h
              jmp short @f

t3 db 'INT 31,501 success !',0Dh,0Ah,24h

@@: mov cx,1
    xor ax,ax
    int 31h         ; allocate descriptor for code
    mov si,ax
    xor ax,ax
    int 31h         ; allocate descriptor for data
    mov di,ax
    mov dx,cs       ; Find out where we are ... suspicious Sad
    lar cx,dx
    shr cx,8
    or  cx,0C000h
    mov bx,si
    mov ax,9
    int 31h         ; set code descriptor access rights
    mov dx,ds
    lar cx,dx
    shr cx,8
    or  cx,0C000h
    mov bx,di
    int 31h             ; set data descriptor access rights
    pop ecx             ; Our new possibly buggy linear address
    shl ecx,4
    mov dx,cx
    shr ecx,16
    mov ax,7            ; set descriptor base address
    int 31h
    mov bx,si
    int 31h
    mov cx,0FFFFh
    mov dx,0FFFFh
    mov ax,8            ; set segment limit to 4 GB
    int 31h
    mov bx,di
    int 31h

    mov [$0400],si ;code descriptor
    mov [$0402],di ;data descriptor

      mov   ax,$0900
      mov   edx,t7
      int   $21
      jmp   @f

t7 db 'New segment created !!!',0Dh,0Ah,24h

;====================================================

binname db "hello32.bin",0

@:
        mov     edx, binname
        mov     ax,$3D00
        int     $21
        jc      openfailed
        push ax
 
    mov    ax,0900h
    mov    edx,t8
    int 21h
    jmp @f

t8 db 'Opened !!!',0Dh,0Ah,24h

@@:     pop  bx          ;handle
        mov  ax,[$0402]
        mov  ds,ax  ;Data segment

;        mov    edx,0
;        mov    ecx,$400000
;        mov    ah,3Fh    ; Read 4 MB - commented out Sad 
;        int    $21

         mov eax,$FFFFFFFF
         mov edx,$98765432
         mov ecx,[0]      ; Will crash here Sad(((((((((((((((((((((
         mov eax,$00000000

         pushf
        
         push cs
         pop ds         ;restore ds

        mov ah,3Eh
        int 21h
        popf 
        jc        readfailed

        mov si,[$0400]
        mov ax,[$0402]
        mov     ds,ax 
        push    0
        push    si
        push    dword 0         ;& jump to offset 0

        retfd

openerr db "file not found",13,10,'$'
readerr db "read error",13,10,'$'

openfailed:

        mov   edx,openerr
        mov   ah,9
        int      21h
        mov    ax,4cffh
        int 21h

readfailed:

        mov   edx,readerr
        mov   ah,9
        int      21h

failure:

        mov  ax,$4CFF 
        int  $21

;========================================================

        rb $4000
;END.
    


There is probably a bug in the segment creation ... could someone look
at the code please ?

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 20 Dec 2006, 21:02
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
> ... could someone look at the code please ?

Code:
    pop ecx             ;Our new linear address
    shl ecx,4           ; ??????????????????????
    mov dx,cx
    shr ecx,16
    mov ax,7            ; set descriptor base address
    int 31h
    
Post 21 Dec 2006, 09:15
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
see description of int 31h/ax=7
Post 21 Dec 2006, 14:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
see description of int 31h/ax=7


The thing does not reveal too much:

Code:
8.7 Set Segment Base Address

This function changes the 32-bit linear base address of
the specified selector.

To Call

AX = 0007h
BX = Selector
CX:DX = 32-bit linear base address for segment

Returns

If function was successful:
Carry flag is clear.

If function was not successful:
Carry flag is set.

Programmer's Notes

o This function  will fail if the selector
  specified in BX is invalid.
o Your program  should only  modify descriptors that
  were  allocated    through   the   Allocate LDT
  Descriptors function.
o The high  8 bits of the base address (contained in
  CH) will  be ignored  by 16-bit implementations of
  DPMI.   This is  true even  when running  on 80386
  machines.
    


Code:
    pop ecx             ;Our new linear address
    shl ecx,4           ; ??????????????????????
    mov dx,cx
    shr ecx,16
    mov ax,7            ; set descriptor base address
    int 31h
    


I did not like these calculations already before anyway, I just as suggested
re-used the "2" code with the only marginal patch: new linear address
instead the segment label.

The problem is also that this INT$31/AX=7 call does NOT set the
CARRY flag although it seems to fail. I really hope not to have found a
bug in HDPMI Rolling Eyes

Code:
    mov bx,di
    int 31h           ; set data descriptor access rights
    pop ecx           ; Our new possibly buggy linear address
    mov edx,ecx
    shr ECX,16           
    mov ax,7          ; set descriptor base address CX:DX // CX high
    int 31h           ; Here the bug is created, but flag(C)=0 Sad
    mov bx,si
    int 31h
    


Tried to fix ^^^ the bug, but no effect: still Exception "E" Embarassed

Code:
    mov cx,1
    xor ax,ax
    int 31h         ; allocate descriptor for code
    mov si,ax
    xor ax,ax
    int 31h         ; allocate descriptor for data
    mov di,ax
    mov dx,cs       ; Find out where we are ... suspicious Sad Sad
    lar cx,dx
    shr cx,8
    or  cx,0C000h
    mov bx,si
    mov ax,9
    int 31h         ; set code descriptor access rights
    


Other thing I do not like (but I could be wrong of course) is ^^^ the
"cs" usage here. Is it correct ?

Any additional ideas to fix the bug ?

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 22 Dec 2006, 02:14
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
> The problem is also that this INT$31/AX=7 call does NOT set the
> CARRY flag although it seems to fail.

I already suggested to use FD DebugX. Without being able to use a debugger you will not have much fun in protected-mode. FD DebugX has a 'DL' command displaying the linear base of a selector, which instantly will show if int 31h, ax=0007 has failed or not.

Your code still is small and simple enough for DebugX.

btw, int 31h, ax=0007 will only fail if the selector in BX is "invalid", it accepts *any* linear address in CX:DX.
Post 22 Dec 2006, 09:11
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
I already suggested to use FD DebugX. Without being able to use a debugger you will not have much fun in protected-mode. FD DebugX has a 'DL' command displaying the linear base of a selector


OK, thanks for improving the FreeDOS DEBUG Smile, but I actually can't really
use it since it lacks a docu. A list of improvements against MS-DOG DEBUG
does not really explain how to use it.

I probably will need a debugger one day, but one should NOT it
to find such criminal and obvious bugs.

Quote:

which instantly will show if int 31h, ax=0007 has failed or not.


Code:
    pop ecx             ;Our new linear address
    shl ecx,4           ; ??????????????????????
    mov dx,cx
    shr ecx,16
    mov ax,7            ; set descriptor base address
    int 31h
    


I does no longer fail after I fixed this ^^^ bug. This code is for a real
mode segment label (clarified in other thread in "Main") and obvioulsy
can't work Evil or Very Mad

Code:
 jmp   @f

t7 db 'New segment created !!!',0Dh,0Ah,24h

;====================================================

binname db "hello32.bin",0

@:
        mov     edx, binname
    


And here ^^^ we have the other criminal and obvious bug Evil or Very Mad

Quote:

btw, int 31h, ax=0007 will only fail if the selector in BX is "invalid", it accepts *any* linear address in CX:DX.


OK, there is no bug, it "accepts" *any* junk address, but creates an
inaccessible segment Embarassed

Well, I got my "Hello from my new 4 MB segment" now Smile,
it seems to work, but I probably will discover some problems later ...
please look in here in future also ...

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 22 Dec 2006, 18:05
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Bugs do seem to follow you around NTOSKRNL_VXE, but your program must hold the record for the most bugs in a "hello world!" program Laughing .

You just do not have, the needed ART and remember the best debugger is in your head.
Post 24 Dec 2006, 06:05
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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.