Page 1 of 2

Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 11:40 am
by srg
Hi

Those of you that have their Kernel situated at the top 2 or 1GB of virtual address space, how to you reliably get up to there?

I'm using Grub and I'm getting bogged down in this, what is the best way of having a Kernel at 2-3GB virtual address space.

I know of the way in Tim's Memory management tutorial, I'm also trying to look for a more portable approach.

thanks
srg

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 11:55 am
by Epp

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 12:24 pm
by Pype.Clicker
lol ... how 'portable' would you like your bootstrapping sequence to be while (afaik)
1. GRUB is limitted to the ia-32 architecture
2. the bootprocess in itself is something that is architecture-dependent

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 12:30 pm
by srg
Pype.Clicker wrote: lol ... how 'portable' would you like your bootstrapping sequence to be while (afaik)
1. GRUB is limitted to the ia-32 architecture
2. the bootprocess in itself is something that is architecture-dependent
OK, I meant more with x86-64, but I just wondered about a way of doing it without fidling with segments.

BTW Cheers Epp!!

srg

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 12:37 pm
by Neo
May be this could help

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 2:23 pm
by Pype.Clicker
well, x86-64 still has segments while in 32 bits, right ? so you can still use the segment trick until a workable paging environment is set up and *then* enable long mode ...

no ?

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 3:43 pm
by srg
Pype.Clicker wrote: well, x86-64 still has segments while in 32 bits, right ? so you can still use the segment trick until a workable paging environment is set up and *then* enable long mode ...

no ?
You can't switch to long mode with paging enabled. You have to turn paging off first.

srg

Re:Getting Up to 2-3GB space

Posted: Wed Apr 14, 2004 3:50 pm
by srg
thanks, I've tried to adapt it for my own linker script:
[tt]OUTPUT_FORMAT("elf32-i386")
ENTRY(kernel_start)

physical_address = 0x100000; /* 1MB */
virtual_address = 0xC0100000; /* 4GB + 1MB */

SECTIONS
{
.text virtual_address :
{
code = .;
*(.text)
. = ALIGN(4096);
}

.data . :
{
data = .;
*(.data)
. = ALIGN(4096);
}

.bss . :
{
bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
kernel_end = .;
}[/tt]
But Grub complains about it not fitting into memory, is there something I've done wrong with it?

One thing I could do is change:

.text virtual_address :

to

.text virtual_address : AT(physical_address)

And then the entry point would be at 0x100000, but if I do this, will it ruin my chances of trying to get it to run at 0xC0000000 once paging is running.

I'm finding this whole thing a real headache.

Thanks
srg

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 12:28 am
by Therx
virtual_address = 0xC0100000; /* 4GB + 1MB */
I know nothing about this topic but the line above must be wrong somewhere. 4GB + 1MB != 0xC0100000

???

Pete

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 2:18 am
by srg
Pete wrote:
virtual_address = 0xC0100000; /* 4GB + 1MB */
I know nothing about this topic but the line above must be wrong somewhere. 4GB + 1MB != 0xC0100000

???

Pete
hmm that should be 3GB + 1MB

srg

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 2:19 am
by Candy
Pete wrote: above must be wrong somewhere. 4GB + 1MB != 0xC0100000
Don't debug comments, only code. The code refers to 3GB+1MB, so it is.

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 2:29 am
by Solar
Candy wrote: Don't debug comments, only code. The code refers to 3GB+1MB, so it is.
Erm... the purist I am strongly disagrees. Comments are part of the code. If there's anything that's worse than uncommented code, it's wrongly commented code.

Not to turn this into a discussion of coding style, but bug reports against comments, manuals, or user interface are just as serious as those against code...

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 2:42 am
by srg
Just to bring this back on topic (all comments have been corrected).

with:
.text virtual_address : AT(physical_address)

The VMA is 0xC0100000 and LMA is 0x100000

Even though the program is linked at 0xC0100000, Grub runs it at 0x100000, which is great before paging is enabled, but what if I want to run it at 0xC0100000 with paging enabled?

Otherwise, how do I get Grub to load the one I have just pasted?

srg

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 9:16 am
by Epp
I know nothing about elf so I can't help you.

And sorry it was my wrong comment.
I created it in a couple of minutes because someone needed it. So I didn't realy chech for bad comments.

Re:Getting Up to 2-3GB space

Posted: Thu Apr 15, 2004 10:16 am
by srg
Here is my code for seting up paging, my kernel is linked at 0xC0100000, it's loaded at address is 1MB. Grub states the entry point is 0xC010000C. But according to Bochs, it's running at 1MB I've left out things like the multiboot header:

BTW My Linker script is attached


%define PAGE_SIZE 0x1000
%define KERNEL_PAGE_DIR_LOCATION 0x200000
%define IDENTITY_PGTBL_OFFSET 0x1000
%define VIRTUAL_PGTBL_OFFSET 0x2000
%define PAGE_PRESENT_AND_REWRITEABLE 3

kernel_start:
; Right at this moment
; 1. CS points to a code segment descriptor with base address 0 and limit 4 gig - 1
; 2. DS, SS, ES, FS, and GS point to a data segment descriptor with base address 0 and limit 4 gig - 1
; 3. A20 is enabled
; 4. Paging is disabled
; 5. Interrupts are disabled. No IDT is defined.
; 6. The size and location of the GDT and selector values are undefined.
; Your kernel should create it's own GDT as soon as possible.
; 7. EAX=0x2BADB002
; 8. EBX contains the linear address of (i.e. a pointer to) a block of system and bootstrap information:

; At the moment, the stack is located at an undefined place, as the C Code needs the stack
; for parameters and local variables, this *MUST* first be moved into a defined place
; The Kernel stack shall be 16KB in size (for now) and will be at the end of the kernel image

mov esp, (kernel_end - 0xC0000000) + KERNEL_STACK_END

push ebx

; 1. Set aside space for 1 Page Directory and 2 Page Tables
mov ecx, PAGE_SIZE * 3
.table_clear
mov byte [KERNEL_PAGE_DIR_LOCATION + ecx], 0
loop .table_clear

; 2. Fill the first page table with first 4MB of RAM
; Fill the first 1MB of mappings with identiry addresses
mov eax, KERNEL_PAGE_DIR_LOCATION + IDENTITY_PGTBL_OFFSET
mov ebx, PAGE_PRESENT_AND_REWRITEABLE
mov ecx, 0x1024 ; Number of pages in 1MB
.fill_first_meg
mov dword [eax], ebx
add eax, 4
add ebx, 0x1000
loop .fill_first_meg

; 3. Do the same with the second page table
mov eax, KERNEL_PAGE_DIR_LOCATION + VIRTUAL_PGTBL_OFFSET
mov ebx, PAGE_PRESENT_AND_REWRITEABLE
mov ecx, 0x1024 ; Number of pages in 1MB
.fill_virt
mov dword [eax], ebx
add eax, 4
add ebx, 0x1000
loop .fill_virt

; 4. Put entry for the first page table at offset 0
mov eax, KERNEL_PAGE_DIR_LOCATION
mov dword [eax], KERNEL_PAGE_DIR_LOCATION + IDENTITY_PGTBL_OFFSET
add dword [eax], PAGE_PRESENT_AND_REWRITEABLE

; 5. Put entry for the second page table at offset 768
mov eax, KERNEL_PAGE_DIR_LOCATION + 768
mov dword [eax], KERNEL_PAGE_DIR_LOCATION + VIRTUAL_PGTBL_OFFSET
add dword [eax], PAGE_PRESENT_AND_REWRITEABLE

; 6. Turn Paging on
mov eax, KERNEL_PAGE_DIR_LOCATION
mov cr3, eax
mov eax, cr0
or eax, 0x80000000
mov cr0, eax


Jmp .to_here
.to_here

; 7. .....
Jmp $

Here, according to Bochs, it's still running at 1MB, but does Bochs only show physical adddresses.

In this I have setup two page tables, both have the first 4MB of memory mapped into them, the first of these two are mapped to the first entry of the Page Directory, the second is mapped to entry 768 of the page directory.

I would now like to jump to the top 3GB of memeory as I have mapped this but when I try, I just get a tripple fault.

What am I doing wrong

Thanks
srg


[attachment deleted by admin]