0

I am currently writing a 32 bit kernel for my operating system, but i've stumbled upon a problem.

When trying to clear screen using method from here, bochs crashes with the following message:

[CPU ]prefetch: getHostMemAddr vetoed direct read, pAddr=0xa0000

clear_screen32 method (ran in protected mode):

;================================;
; Clears the screen (in 32 bits) ;
;================================; 
clear_screen32:

    pusha
    cld
    mov edi, vmem
    mov cx, 2000
    mov ah, c_attrib

    mov al, ' ' 
    rep stosw

    mov byte [_xpos], 0
    mov byte [_ypos], 0
    popa
    ret

What could be wrong here?

Edit: i mistyped, it's getHostMemAddr not getHostByAddr

*EDIT2: The error happens at *

rep stosw

if i delete this, code runs fine (but no screen clearing of course)

themorfeus
  • 277
  • 1
  • 3
  • 17
  • I'm assuming that you're in protected mode when you call this subroutine(?). Do you have an entry for the video memory in your GDT? – Michael Aug 08 '13 at 15:00
  • @Michael Yes i am, and yes i do. I should also point out that printing the text using the method from the same site works perfectly fine. – themorfeus Aug 08 '13 at 15:14
  • How about ES? Try to replace rep stosw with mov word [edi], ax/add edi, 2/dec ecx/jnz .loop - it will work in DS. – johnfound Aug 08 '13 at 16:28
  • Why are you using "rep stosw" when "rep stosd" is available? – Brian Knoblauch Aug 08 '13 at 18:35
  • `rep stosw` is just a bit "easier" to understand, since each character is two bytes (the attributes, and the character code itself) – Drew McGowen Aug 08 '13 at 18:39

1 Answers1

-2

Welp, seems that bochs developers are (or maybe i am) a little bit stupid, as CX register is nonexistent in bochs.
I found out when i dumped register info to screen while debugging. The CX register simply does not exist there.

My solution? Being in 32 bit mode, and having access to 32 bit registers I simply replaced the CX register to ECX, which did work, and screen got cleared perfectly.

themorfeus
  • 277
  • 1
  • 3
  • 17
  • 9
    It can't be true. This effect is because in 32bit mode "rep" instruction works on ecx, but there was some garbage in the higher 16 bit of ecx. – johnfound Aug 08 '13 at 16:34
  • Oh, didn't know that. But it's weird that cx doesn't appear when using info r in debug mode... – themorfeus Aug 08 '13 at 16:57
  • 7
    `cx` is just the lower 16 bits of `ecx` – Drew McGowen Aug 08 '13 at 18:38
  • Even if you are in 16-bit real mode, you can still access 32bit registers via the Operand Size Prefix (0x66). Your assembler will likely do this for you when you want to access a register as such. – Levente Kurusa Aug 16 '13 at 06:33
  • By Operand Size prefix or Address Size prefix, when used in address (note: those two are not exclusive). – Griwes Sep 19 '13 at 10:28