flat assembler
Message board for the users of flat assembler.

Index > DOS > CWSDPMI and 0x100 allocate DOS memory

Author
Thread Post new topic Reply to topic
hodbogi



Joined: 14 Oct 2020
Posts: 2
hodbogi 20 Oct 2020, 23:55
Hello, I have been looking through some examples and resources both here and anywhere I can find and I am not quite sure why my code does not appear to work.

I am trying to test allocating DPS memory and writing to it (just 0's for now) but every time I allocate the page and then write to it I get a general protection fault. Looking at the DPMI 1.0 spec it says I am not supposed to modify any LDT information for DOS allocations, so I avoided that.

IO am using CWSDPMI and the code is as follows:

Code:
mov ax, 0x100 ; Allocate DOS memory
mov bx, 2 ; 32 bytes
int 0x31 ; DPMI
jc . end ; Error = carry set

mov es, dx ; selector is in dx
mov di, ax ; Offset is in ax
mov cx, 10 ; Just 10 bytes to copy for now
mov al, 0 ; Fill with 0s.
cld ; Increment di + 1 per rep
rep stosb ; Store string data

.end: ; Somewhere fuirther down in the code.

    


The general protection fault I have found happens exactly at the rep stosb line. I must be missing something?
Note: If there are typos in the code it is likely because I retyped all of this looking at my other computer screen.
Post 20 Oct 2020, 23:55
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 21 Oct 2020, 00:59
DX is the pmode selector
AX is the real mode segment

The offset should be 0
Post 21 Oct 2020, 00:59
View user's profile Send private message Reply with quote
hodbogi



Joined: 14 Oct 2020
Posts: 2
hodbogi 21 Oct 2020, 16:11
Ah that is actually making more sense now, I'm more of a 65xx / 68xx kind of person so I'm half confused about protected mode selectors and real mode segments, etc. I'm assuming it's not as simple as throwing ax into es and 0 into di and using stosb from there, right? that causes a protection fault as well. Do I have to convert it into a physical address or something somehow and go from there? By the nature of what I read about how stosb works, it doesn't seem that way. I'd hate to ask but I would definitely appreciate an example that I can study of how this would work in particular with function 0x100 like used here (a couple examples I looked at online to accomplish certain tasks used it), so that I can learn a little more about that aspect.
Post 21 Oct 2020, 16:11
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 21 Oct 2020, 19:43
When you are using that memory, you are in protected mode and would use DX:0 to access it.
Usually you would allocate DOS memory to use with a real mode DOS or BIOS call, in that case you pass AX:0 as the memory address.
Post 21 Oct 2020, 19:43
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.