Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

DPMI code from .COM file? (Developers)

posted by ecm Homepage E-mail, Düsseldorf, Germany, 11.05.2020, 14:59

> To narrow the question:
> In FASM distribution is a example file USEDPMI.ASM
> It prints a message "Hello from protected mode!"
> Here is the listing:

I edited your post to put the listing into BB-code [code] tags.

> format MZ
> heap 0 ; no additional memory
>
> segment loader use16

Insert whatever is used by FASM for flat .COM files.

> push cs
> pop ds

This is probably fine.

> mov bx,si ; allocate memory for DPMI data
> mov ah,48h
> int 21h
> jc error

Before this you need to shrink the process's memory block because flat .COM files are always loaded with max alloc = FFFFh. Shrink it to 1000h paragraphs (64 KiB), or if you want to shrink it smaller insure that the stack is below that. Eg (for NASM, adjust to whatever FASM needs):

        cpu 8086
        org 256

startprogram:
        [...]
        cmp sp, stack_end
        jb error
        mov sp, stack_end
        mov bx, ( (stack_end - startprogram) + 256 + 15 ) >> 4
        mov ah, 4Ah
        int 21h
        jc error
        [...]

        align 2
endprogram:
stack_end: equ endprogram + 512


> mov ecx,main
> shl ecx,4
> mov dx,cx
> shr ecx,16
> mov ax,7 ; set descriptor base address
> int 31h
> mov bx,si
> int 31h

This needs to change. Easiest is putting the "main" or "start" label in the same segment as the .COM entrypoint. In that case replace the "mov ecx, main" with:

        mov cx, cs
        movzx ecx, cx


If you want to keep using different segments then in NASM you'd need "section main vstart=0" and load ecx with CS plus whatever is the size in paragraphs of the PSP plus the section "loader". Not sure how to do that in FASM.

---
l

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 246 users online (1 registered, 245 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum