Page 2 of 3
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 12:38 pm
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.
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 1:50 pm
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.
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 2:15 pm
by makuc9
Hmmm... Is this better?
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?
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 3:22 pm
by dozniak
makuc9 wrote:Hmmm... Is this better?
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)
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 5:18 pm
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
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 6:59 pm
by Mikemk
dozniak wrote:(Assuming you are able to write byte printing function)
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.
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 8:01 pm
by Opcode
m12 wrote:@Opcode, your function trashes the bottom (top) of the stack.
Where?
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 8:51 pm
by Mikemk
BP is the base pointer of the stack. changing it effectively moves the stack.
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 9:08 pm
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
Re: (hardware) reserved memory & GDT question
Posted: Mon Apr 22, 2013 9:43 pm
by Opcode
Hehe, you had wondering for a few minutes. I thought you got .errorExit and .exitLoop mixed up.
Re: (hardware) reserved memory & GDT question
Posted: Tue Apr 23, 2013 12:26 am
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.
Re: (hardware) reserved memory & GDT question
Posted: Tue Apr 23, 2013 1:08 pm
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.
Re: (hardware) reserved memory & GDT question
Posted: Tue Apr 23, 2013 4:06 pm
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.
Re: (hardware) reserved memory & GDT question
Posted: Wed Apr 24, 2013 3:29 am
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.
Re: (hardware) reserved memory & GDT question
Posted: Wed Apr 24, 2013 7:10 am
by Mikemk
lol @ iansjack. That actually came out of
Stack. Rereading through that, I guess I misunderstood/misread.