(hardware) reserved memory & GDT question

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
makuc9
Member
Member
Posts: 33
Joined: Sun Mar 03, 2013 3:27 pm

Re: (hardware) reserved memory & GDT question

Post by makuc9 »

dozniak wrote:Are you familiar with concept of LITTLE ENDIAN architecture (of which all Intel processors in use are)?
Yes, I am. But doesn't that mean that only quad words, double words, words are written the other way? (at least that's how they were stored in binary files that I've been compiling when working on first stage bootloader).

Anyway...Fixing create memory map function & print memory map function.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: (hardware) reserved memory & GDT question

Post by dozniak »

makuc9 wrote: Yes, I am. But doesn't that mean that only quad words, double words, words are written the other way?
Yes, but you only print qwords and dwords in regards to e820 function, so this question seems moot to me.
Learn to read.
makuc9
Member
Member
Posts: 33
Joined: Sun Mar 03, 2013 3:27 pm

Re: (hardware) reserved memory & GDT question

Post by makuc9 »

Hmmm... Is this better?
Image
Altough I still don't know what the heck is wrong with the first line (second qword)...

I changed each memory map entry size to outputed cl and printing function now prints only qwords and the last dword reversed. Should I reverse the whole entries?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: (hardware) reserved memory & GDT question

Post by dozniak »

makuc9 wrote:Hmmm... Is this better?
Image
It looks completely off.
Can you show byte-by-byte hex dump of what e820 returns? (Assuming you are able to write byte printing function)
Learn to read.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: (hardware) reserved memory & GDT question

Post by Opcode »

Try this

Code: Select all

;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
;³ FUNCTION     ³ BuildE820Map                                                 ³
;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
;³ DESCRIPTION  ³ Build an E820 map at ES:DI                                   ³
;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
;³ ENTRY        ³ ES:DI - Starting location to store the memory map            ³
;³              ³                                                              ³
;³              ³ NOTE: Assumes ES:DI doesn't wrap around                      ³
;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
;³ EXIT         ³ CF - Set on error                                            ³
;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
;³ REMARKS      ³ Output For @ ES:DI                                           ³
;³              ³                                                              ³
;³              ³       Count (4 Bytes)      OFFSET      0                     ³
;³              ³       Entry 1 (24 Bytes)   OFFSET     28                     ³
;³              ³       .                                                      ³
;³              ³       .                                                      ³
;³              ³       .                                                      ³
;³              ³       Entry n (24 Bytes)   OFFSET (n * 24) + 4               ³
;³              ³                                                              ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
BuildE820Map:
	pushad
	mov	DWORD [ES:DI], 0x00000000
	mov	bp, di
	add	di, 4
	xor	ebx, ebx

.nextEntry:
	mov	DWORD [ES:DI + 20], 0x00000001
	mov	eax, 0xE820
	mov	ecx, 24
	mov	edx, 0x0534D4150 ;'SMAP'
	int	0x15
	jc	.exitLoop
	cmp	eax, 0x0534D4150 ;'SMAP'
	jne	.exitLoop
	cmp	ecx, 20
	jl	.exitLoop
	cmp	ecx, 24
	jg	.exitLoop

	; We have a valid entry
	inc	DWORD [ES:BP]
	add	di, 24
	cmp	ebx, 0
	jne	.nextEntry

.exitLoop:
	cmp	DWORD [ES:BP], 0x00000000
	popad
	je	.errorExit
	clc
	ret

.errorExit:
	stc
	ret
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: (hardware) reserved memory & GDT question

Post by Mikemk »

dozniak wrote:(Assuming you are able to write byte printing function)
Opcode wrote:Try this

Code: Select all

...
You're assuming quite a bit. I don't think he knows what it is.

@Opcode, your function trashes the bottom (top) of the stack.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: (hardware) reserved memory & GDT question

Post by Opcode »

m12 wrote:@Opcode, your function trashes the bottom (top) of the stack.
Where?
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: (hardware) reserved memory & GDT question

Post by Mikemk »

BP is the base pointer of the stack. changing it effectively moves the stack.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: (hardware) reserved memory & GDT question

Post by Brendan »

Hi,
m12 wrote:BP is the base pointer of the stack. changing it effectively moves the stack.
For high level languages (e.g. C), BP/EBP/RBP is used as the stack frame pointer (if the compiler's optimiser hasn't been told to omit the frame pointers).

For assembly you're not restricted to HLL conventions - BP/EBP/RBP is just another register and you can do whatever you like with it.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: (hardware) reserved memory & GDT question

Post by Opcode »

Hehe, you had wondering for a few minutes. I thought you got .errorExit and .exitLoop mixed up.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: (hardware) reserved memory & GDT question

Post by dozniak »

Opcode wrote:

Code: Select all

	cmp	ecx, 20
	jl	.exitLoop
	cmp	ecx, 24
	jg	.exitLoop

	; We have a valid entry
	inc	DWORD [ES:BP]
	add	di, 24
Shouldn't you be adding ecx to edi here? Not just 24. Because if ecx was 20 in comparison above, you're just screwing up the map?

Edit: oh, wait, I think I see. So you're putting everything into a fixed-size map, sorry for the confusion.
Learn to read.
makuc9
Member
Member
Posts: 33
Joined: Sun Mar 03, 2013 3:27 pm

Re: (hardware) reserved memory & GDT question

Post by makuc9 »

m12 wrote:
dozniak wrote:Can you show byte-by-byte hex dump of what e820 returns? (Assuming you are able to write byte printing function)
You're assuming quite a bit. I don't think he knows what it is.
Thank you m12, you were really helpful here. I know what a hex dump is and I already posted it once (which I only seperated with spaces where I first thought qwords were) altough it was 24 bytes in length! (But in my function I was increasing destination source register by 24, so entries shouldn't be that much off. I mean first 20 bytes are the same, right? E820h function does not really "care" about ds, it only "cares" about bx value - well, not only about bx, but you should understand what I meant). Than you all were telling me to use little endian encoding while no-one mentioned how to reverse entries: as a whole or as qwords. I also edited MM generation function to use returned CL as a size for each entry and not 24 bytes as previously specified by me. There is not really neccessary for you to insult me, you know. Sure, I just turned 18 (3 weeks ago). Sure I am not learning programming on any programming school (I am at general high school, or secondary school, don't know how is it more proper to say, one of the best in my country) which unfortunately does not cover this topic, only some Microsoft Office Word, PP, Excel and Access crap (and some very basic HTML structures - actually only how to edit existing templates downloaded from the internet). So yea, I've learnt PHP, HTML (& CSS2.1) and C++ to a quite high degree myself and lately (in the passed 1-2 months) I have also being learning Assembly. I did successfully completed the first stage of bootloader for FAT32 (USB) drive (and I do not mean only copy&pasting it - I did made some mistakes in it, you can find my questions about it here, but neverthless, it is completed now), which can load a file from FAT 32 Byte Directory Entry Structure (I guess only up to 480KB in size - Yes, I load it in 0x00007E00 address which is only 480.5KB in size) and pass control to it. I have also programmed some other, different kinds of testing stuff to get more accustumed to assembly (also number printing function for numbers higher than 9 and as you can see also in hex number - hex printing even displays numbers in even format - adds preleading zero). I am only not yet that familiar with x86 & x64 architectures, so just correct me if I am wrong, no need to insult me (I am also not a native english speaker, so I DO confuse some explaination and misunderstand others).

Anyway, will return here tomorrow (I have to continue preparing myself for examination which I have tomorrow, so I only came online to check emails and check responses here, because I got alerted by mail notification).

Regards.
Last edited by makuc9 on Wed Apr 24, 2013 7:06 am, edited 1 time in total.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: (hardware) reserved memory & GDT question

Post by Mikemk »

makuc9 wrote:There is not really neccessary for you to insult me, you know.
I never insulted you.
Sure, I just turned 18 (3 weeks ago).
Firstly, you're older than me. This, however, is irrelevant.
Sure I am not learning programming on any programming school
That's the best way to learn. (No joke here).
(I am at general high school, one of the best in my country) which unfortunately does not cover this topic, only some Microsoft Office Word, PP, Excel and Access crap (and some very basic HTML structures - actually only how to edit existing templates downloaded from the internet).
More than my high school. We're stuck with Open Office, and no programming. I taught myself everything I know.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: (hardware) reserved memory & GDT question

Post by iansjack »

m12 wrote:BP is the base pointer of the stack. changing it effectively moves the stack.
Hmm.
m12 wrote:I taught myself everything I know.
It's very honest of you to take the blame. :wink:
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: (hardware) reserved memory & GDT question

Post by Mikemk »

lol @ iansjack. That actually came out of Stack. Rereading through that, I guess I misunderstood/misread.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Post Reply