Problems with e820 mapping

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
User avatar
lollynoob
Member
Member
Posts: 150
Joined: Sun Oct 14, 2007 11:49 am

Problems with e820 mapping

Post 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.
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Problems with e820 mapping

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Problems with e820 mapping

Post 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
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Problems with e820 mapping

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Problems with e820 mapping

Post 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.
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Problems with e820 mapping

Post 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:
Post Reply