OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 15, 2024 10:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 12:38 pm 
Offline
Member
Member

Joined: Sun Mar 03, 2013 3:27 pm
Posts: 33
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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 1:50 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 2:15 pm 
Offline
Member
Member

Joined: Sun Mar 03, 2013 3:27 pm
Posts: 33
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?


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 3:22 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 5:18 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 2:50 pm
Posts: 29
Try this

Code:
;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
;³ 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


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 6:59 pm 
Offline
Member
Member

Joined: Sat Oct 22, 2011 12:27 pm
Posts: 409
dozniak wrote:
(Assuming you are able to write byte printing function)

Opcode wrote:
Try this
Code:
...

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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 8:01 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 2:50 pm
Posts: 29
m12 wrote:
@Opcode, your function trashes the bottom (top) of the stack.


Where?


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 8:51 pm 
Offline
Member
Member

Joined: Sat Oct 22, 2011 12:27 pm
Posts: 409
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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 9:08 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Mon Apr 22, 2013 9:43 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 2:50 pm
Posts: 29
Hehe, you had wondering for a few minutes. I thought you got .errorExit and .exitLoop mixed up.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Tue Apr 23, 2013 12:26 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Opcode wrote:
Code:
   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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Tue Apr 23, 2013 1:08 pm 
Offline
Member
Member

Joined: Sun Mar 03, 2013 3:27 pm
Posts: 33
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.

Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Tue Apr 23, 2013 4:06 pm 
Offline
Member
Member

Joined: Sat Oct 22, 2011 12:27 pm
Posts: 409
makuc9 wrote:
There is not really neccessary for you to insult me, you know.

I never insulted you.
Quote:
Sure, I just turned 18 (3 weeks ago).

Firstly, you're older than me. This, however, is irrelevant.
Quote:
Sure I am not learning programming on any programming school

That's the best way to learn. (No joke here).
Quote:
(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.


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Wed Apr 24, 2013 3:29 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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:


Top
 Profile  
 
 Post subject: Re: (hardware) reserved memory & GDT question
PostPosted: Wed Apr 24, 2013 7:10 am 
Offline
Member
Member

Joined: Sat Oct 22, 2011 12:27 pm
Posts: 409
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 69 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group