Page 1 of 1

Trouble With Loading Memory in Protected Mode

Posted: Mon Sep 19, 2011 6:46 pm
by ElasticRaven
Hello. After some work, I managed to get into 32-bit protected mode. I can access some memory correctly, but not all.

Code: Select all

[bits 16]
[org 0x8000] ; stage1 loads me at 0x0000:0x8000
...
set video mode, disable interrupts, enable A20, load gdt, set cr0 LSB
jmp 0x8:pmode_start
...
pmode_start:
[bits 32]
mov  al,[tmpvar]
mov  ebx,[tmpvar2]
mov  [0xb8000+ebx],al
mov  byte [0xb8000+ebx+1],0x7

jmp hang

tmpvar db 'A'
tmpvar2 dw 0
I would expect this to write 'A' at the top left corner. It does not. However, if I replace "[tmpvar2]" with "0", it does write 'A'. So it seems like I can get to tmpvar, but not tmpvar2. Can anyone shed some light?

Re: Trouble With Loading Memory in Protected Mode

Posted: Mon Sep 19, 2011 7:02 pm
by gerryg400
I think you need

Code: Select all

tmpvar2 dd 0
or else you will be loading garbage into the upper word of ebx

Re: Trouble With Loading Memory in Protected Mode

Posted: Tue Sep 20, 2011 3:30 am
by egos
Usually following logic is used:

Code: Select all

  movzx ebx,[superpos]
  mov [videobuf+ebx*2],al
  mov byte [videobuf+ebx*2+1],7
  ...
  superpos dw 0

Re: Trouble With Loading Memory in Protected Mode

Posted: Tue Sep 20, 2011 6:49 am
by ElasticRaven
gerryg400 wrote:I think you need

Code: Select all

tmpvar2 dd 0
or else you will be loading garbage into the upper word of ebx
Facepalm :shock: It works now.... Thanks.