Memory Remapping

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.
pskyboy

Re:Memory Remapping

Post by pskyboy »

Hey Tim

Thanks for that i rechecked the source code, whoops wish i had seen that earlier before i started hacking bochs. I guess i was so keen to blame somethign else rather then my bootloader. I have put an apology on the Bochs developer board and feel highly humbled now. I will quietly walk away and hang my head in shame.

Peter
Tim

Re:Memory Remapping

Post by Tim »

What does loading at the 3GB (virtual) mark have to do with the CPU discarding the top 8 bits of your GDT base? As long as the linear address of your GDT is below 16MB you're OK. That is, there's no problem as long as your put your kernel below 16MB physical.

Later, when you have paging enabled, you will probably want to reload the GDT again, and at that point it will be above linear 16MB because of paging. Then the CPU will take notice of all the bits in your GDTR.base, not just the bottom 24.
pskyboy

Re:Memory Remapping

Post by pskyboy »

But surely for the GDT to load properly you need to use a messy pointer. So for instance i have 0x40100000 as the base in my GDT Code and Data selector so that when i jump to 0xC0000000 it remaps to 0x100000, is thsi correct?

I then set my GDTptr to GDT - 0x40100000 so that when a GDT access is done it remaps it to the right place which is below 1Mb. This therfore produces a value greater then 24Bits that needs to go in the GDT's base pointer.

Peter
Tim

Re:Memory Remapping

Post by Tim »

I then set my GDTptr to GDT - 0x40100000 so that when a GDT access is done it remaps it to the right place which is below 1Mb. This therfore produces a value greater then 24Bits that needs to go in the GDT's base pointer.
The physical GDT base pointer can't be more than 24 bits in length unless the GDT's physical really is above the 16MB mark. You're saying that the 'right place' for your GDT is below 1MB, so GDTR.base < 0x100000.
pskyboy

Re:Memory Remapping

Post by pskyboy »

Okay i might have missed the point here. Does the GDT use a physical address to find its tables or a Logical address. I was assuming it used a logical address so that if you say had the GDT tables at the 64Kb after protected mode was enabled you would need to subtract 0x40100000 from the GDT address so that the physical address is 64Kb.

Have i got this completly wrong?

Peter
pskyboy

Re:Memory Remapping

Post by pskyboy »

Okay can someone outline the exact steps i need to take to be able to link my kernel at 3Gb but be able to load it at 1Mb then jump to it as i am having real trouble getting this to work. I understand the theory behind what do but am getting lost in teh subtlties. for instance:-

1) How does the GDT pointer point to the tables by Physical or Linear memory address

2) Do i need to use two GDT's to get this to work?


Cheers Peter
Tim

Re:Memory Remapping

Post by Tim »

1) LGDT uses a linear address. In real mode, this is seg * 16 + ofs. In 32-bit flat, this is a virtual address. It is not a 'messy pointer'.

2) No
shad

Re:Memory Remapping

Post by shad »

pskyboy did you ever figure it out? Because i think we are having the same problem.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Memory Remapping

Post by distantvoices »

1. Sometimes I feel as if I talk to an ill horse to lead it to the water.

2. Link your kernel to 0xc0000000.
3. load your kernel to 0x100000.
4. have a constant in your startup stub: ADDRESSCORR equ 0xbff00000.
5. for every label, be it idt, be it a function, say the following: LABEL - ADDRESSCORR.
6. Set up ZERO BASED DESCRIPTORS in your. Save you the **** for the first time. Gosh!
7. This I have found in the VALEO kernel thingy: May be it is of help or you:

Code: Select all

// Map the core page table entry (for 0x80000000) into the page directory
        movl     (CorePageTable - ADDRADJUST), %eax
        orl      $3, %eax
        movl     (PageDirectory - ADDRADJUST), %edi
        addl     $0x800, %edi
        movl     %eax, (%edi)

        // Map the page tables entry (for 0x8FC00000) into the page directory
        movl     (PageTables - ADDRADJUST), %eax
        orl      $3, %eax
        movl     (PageDirectory - ADDRADJUST), %edi
        addl     $0x8FC, %edi
        movl     %eax, (%edi)
for further snippets, look for either this valeo-kernel or other paging examples.

Have a nice day.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
pskyboy

Re:Memory Remapping

Post by pskyboy »

Okay i finally got it to work, cheers for all your help although some was far from helpful. I think im going to write a tutorial on doing this cos its far from clear. As usual it was just a little sublty that was causing all the problems.

Peter
Post Reply