problems with memory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
DIGIT4L_PUNK

problems with memory

Post by DIGIT4L_PUNK »

I have a problem: I wrote a procedure which enters big-real mode. it works (i have checked it) it also enables a20 gate through KBC (the program checs for A20-ON bit set in the IO register.. and i seems to be SET) well, here's the code snippet:
-----------------------------------
???call enable_32

(1)???lea esi,[image_buff]
???mov edi,0x000b8000
???mov ecx,512
???cld
a32???rep movsb

(2)???lea esi,[image_buff]
???mov edi,0x00200000
???mov ecx,512
a32???rep movsb
-------------------------------------
well, snippet (1) works. and snippet (2) doesn't work :(
oh, one and useful note, I have Compaq DeskPro (based on P1) and could it be the reason of that?
Phugoid

Re:problems with memory

Post by Phugoid »

Does that machine have more than 2MB of RAM?
DIGIT4L_PUNK

Re:problems with memory

Post by DIGIT4L_PUNK »

it has 24MBytes of RAM. I have tested the code on 486 machine and it did the same there too so there must be something wrong in the xode ??? :-\
DIGIT4L_PUNK

Re:problems with memory

Post by DIGIT4L_PUNK »

ok, here's the code:

Code: Select all

[BITS 16]
[ORG 0x100]

   call enable_32
   call enable_a20

   lea esi,[image_buff]
   mov edi,0x00100000
   mov ecx,512
   cld
a32   rep movsb
   cmp byte [es:0x00100000],'a'
   je  E3
   mov ah,0x09
   lea dx,[M0]
   int 0x21
   ret
M0   db 'problems with memory :(',13,10,'$'

E3:   sti
   mov ah,0x09
   lea dx,[E3.M0]
   int 0x21
   ret
M0   db 'ok',13,10,'$'

image_buff times 512 db 'a'

   %include '..\include\loader.inc'
DIGIT4L_PUNK

Re:problems with memory

Post by DIGIT4L_PUNK »

I'll add some GATE A20 testing code... ::)
DIGIT4L_PUNK

Re:problems with memory

Post by DIGIT4L_PUNK »

this is the modified code. changes were made to test the A20 state:

Code: Select all

[BITS 16]
[ORG 0x100]

   call enable_32
   call enable_a20

   mov eax,dword[es:0x00207000]
   cmp eax,dword[es:0x00307000]
   jne E3
   mov ah,0x09
   lea dx,[M0]
   int 0x21
   ret
M0   db 'problems with memory :(',13,10,'$'

E3:   mov ah,0x09
   lea dx,[E3.M0]
   int 0x21
   ret
.M0   db 'ok',13,10,'$'

   %include '..\include\loader.inc'
it showed "problems with memory" for different values (not random values ofcourse) it showed, that the x86-specific memory-wrapping is still enabled. ??? ::)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:problems with memory

Post by Brendan »

Hi,

Just curious, but which assembler?

For NASM, in 16 bit mode it will silently truncate 32 bit memory references unless there's a 32 bit register in the effective address. For example:

Code: Select all

   mov eax,dword[es:0x00207000]
   cmp eax,dword[es:0x00307000]
Will become:

Code: Select all

   mov eax,dword[es:0x7000]
   cmp eax,dword[es:0x7000]
To fix this, you need to put the "dword" keyword inside the square brackets - for e.g.:

Code: Select all

   mov eax,dword [dword es:0x00207000]
   cmp eax,dword [dword es:0x00307000]
Alternatively, if there's a 32 bit register this isn't needed - for e.g. you could do:

Code: Select all

   mov edi,0x00207000
   mov eax,dword [es:edi]
In this case NASM knows it's a 32 bit address because you've used EDI instead of just DI. The same sort of thing applies to more complex effective addresses. For example, this works:

Code: Select all

   mov edi,0
   mov eax,dword [es:edi+0x00207000]
If the "dword" keyword is outside of the brackets, then it's telling NASM to use 32 bit data values (not 32 bit addresses). For example, all of these instructions will generate the exact same code (in 16 bit mode):

Code: Select all

   mov eax,dword [es:0x00207000]
   mov eax,dword [es:0x7000]
   mov eax,[es:0x00207000]
   mov eax,[es:0x7000]
   mov eax,dword [word es:0x00207000]
   mov eax,dword [word es:0x7000]
   mov eax,[word es:0x00207000]
   mov eax,[word es:0x7000]
The "dword" keyword is only needed outside of the brackets when NASM can't figure out the size of the data. Normally it isn't needed because the source or destination is a register, and NASM can work out the size of the data from the size of the register used. For example, NASM will complain about these lines because it can't figure out what size the data is:

Code: Select all

   mov [0x1234],0
   movzx eax,[0x1234]
Instead you'd need to change these to something like:

Code: Select all

   mov dword [0x1234],0
   mov word [0x1234],0
   mov byte [0x1234],0
   movzx eax,byte [0x1234]
   movzx eax,word [0x1234]
Anyway, compare your source code with the output from a disassembler to see if it looks the same....


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
DIGIT4L_PUNK

Re:problems with memory

Post by DIGIT4L_PUNK »

that's ok guys :) i've fixed the problem. Brendan, your comment is right, 10x. I replaced
mov [es:0x000b8000],'1234' with
mov [es:DWORD 0x000b8000],'1234'
and it helped. there were also some errors in the flat-real mode procedure. I've fixed them too. so the code just works fine :) ;D
Post Reply