Page 1 of 1

Problems with e820 mapping

Posted: Wed Aug 13, 2008 7:23 pm
by lollynoob
Hey,
I've been working on a bootloader for a bit now, and currently I'm stuck at memory mapping; I've written an implementation for getting a memory map using function e820, but it fails in QEMU 0.9.1 and bochs 2.3.5. It doesn't crash, it just seems like function e820 doesn't exist. Now, this can't be the case, since both of these emulators can run operating systems which use function e820 for a memory map, so does anyone know where I could be going wrong? Here's my implementation:

Code: Select all

me820:
	xor	ebx,ebx
	mov	ecx,20
	mov	es,bx
	mov	di,BEGIN
.next:
	mov	eax,0xe820
	mov	edx,'SMAP'
	xor	di,di

	int	0x15
	jc	stopmap		;Function unsupported

	cmp	ecx,20
	jne	stopmap		;Wrong structure size

	cmp	eax,'SMAP'
	jne	stopmap		;Incorrect BIOS revision

	inc	dword [mem_e820n]
	add	di,cx
	
	cmp	di,BEGIN+0x1000
	jae	stopmap		;Memory map longer than 4kb, error(?)

	cmp	ebx,0
	jne	.next
Thanks in advance.

Edit: Welp, turns out

Code: Select all

mov edx,'SMAP'
is not the same as

Code: Select all

mov edx,0x534d4150
Thanks NASM.

Re: Problems with e820 mapping

Posted: Thu Aug 14, 2008 2:43 am
by cyr1x
lollynoob wrote: Edit: Welp, turns out

Code: Select all

mov edx,'SMAP'
is not the same as

Code: Select all

mov edx,0x534d4150
Thanks NASM.
A string is always a pointer.

Re: Problems with e820 mapping

Posted: Thu Aug 14, 2008 5:29 am
by AJ
cyr1x wrote:A string is always a pointer.
?

I think the problem was more the endianness of the value moved in to edx. In this case, a string is not a pointer, it is 4 8 bit characters which are converted from ASCII to their numeric equivalents.

he problem here is that you would have to specify:

Code: Select all

mov edx, 'PAMS'
to get the same result.

Cheers,
Adam

Re: Problems with e820 mapping

Posted: Thu Aug 14, 2008 10:12 am
by cyr1x
'SMAP' is not directly converted to the equal "hex-sequence", but it is moved to the data-section and is replaced by a pointer to it.
Clear?

Cheers.

EDIT:
Actually I don't now if it is done by NASM, but most assembler's I used do it that way.
Can somebody prove that?

EDIT2:
Ok I think I disproved myself. It is converted to a byte-sequence
Shame on me. :oops:

EDIT3: :mrgreen:
'SMAP' equals 0x534D4150 so edianness shouldn't be a problem.
Tried it with

Code: Select all

mov eax, 'SMAP'
cmp eax, 0x534D4150

Re: Problems with e820 mapping

Posted: Thu Aug 14, 2008 1:49 pm
by AJ
cyr1x wrote:'SMAP' is not directly converted to the equal "hex-sequence", but it is moved to the data-section and is replaced by a pointer to it.
Clear?
...
EDIT:
Actually I don't now if it is done by NASM, but most assembler's I used do it that way.
Can somebody prove that?
I certainly wouldn't trust an assembler that moved my data around randomly like that. I checked my answer on Bochs debugger before posting and it's probably a good idea to check things out before attempting a patronising answer in future.

Re: Problems with e820 mapping

Posted: Fri Aug 15, 2008 5:25 am
by cyr1x
AJ wrote: ... and it's probably a good idea to check things out before attempting a patronising answer in future.
I agree totally :mrgreen:.

But anyway I hadn't the time to test it, so forgive me great AJ. :mrgreen: