Page 1 of 1

Question on clearing RAM

Posted: Sun Sep 08, 2013 10:29 am
by tlf30
I am running into a problem that I have never had before...

I am trying to clear the RAM from 0x0000:0x0000 to 0x0000:0x0100 in x86 real mode. To do this I built a loop, but my loop is only running 0x40 times... Any ideas?

Note: FS has already been set to 0x0000 when I setup my stacks.

Code: Select all

;Clear ram from 0x0000 to 0x0100
	mov bx, 0x0000 ;Counter
		
	.clear_loop:
		mov byte [fs:bx], 0x00 ;Clear value at (FS:BX) 0x0000:BX
		
		inc bx ;Increment counter, BX
		
		%if DEBUG_CLEAR_LOOP_PRINT_ADDRESS
			push bx ;Store BX, counter
			mov dx, bx ;Move BX into DX for print of counter
			mov bx, 0x000F ;Bios color white for print
			call print_dx ;Print DX, value of counter
			pop bx ;Restore BX, counter
		%endif
		
		;Check if done
		cmp bx, 0x0100
		jbe .clear_loop ;If BX is less than or equal to 0x0100, go back to .clear_loop
		;if done continue on...


Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 10:39 am
by iansjack
That's not a very efficient routine, but still - why not just single-step through it in a debugger to find out why it's not doing what you think it should?

Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 10:48 am
by tlf30
I understand it is very inefficient, but I am debugging it for a friend... The piece of code is in a boot loader so I am unsure on how to run it in a debugger... Any suggestion?

Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 10:57 am
by dozniak
Perhaps you're overwriting the IVT?

Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 10:59 am
by tlf30
I never thought of that, but it would explain a lot...

Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 11:14 am
by tlf30
You were correct! I changed the address range to 0x0010:0x0000 - 0x0010:0x0100 and now it is stuck on some really poor disk reading code that I need to go over.

Thank You!

Re: Question on clearing RAM

Posted: Sun Sep 08, 2013 11:15 am
by iansjack
You could debug in an emulator - Bochs, qemu, SimNow. As already said, you will be overwriting the IVT so, if you haven't disabled interrupts or if you are using BIOS functions, the routine won't complete.