I´m trying to load and exec a flat binary file compiled in gcc with nasm
I link that file into 0x0000000
and at my kernel I load into a position physical e.g 0x131000
now I have that question. how do I setup my page_table and page_dir for
that new process ?
I need to setup the first page_entrie for page table right ?
but how do I get the right value and put on it ?
like page_table[0] = (((0x131000 >> 12) & 0x3ff) << 12);
?
that calc doesn´t works
and on ip value should I put " 0 " for starting ?
loading flat binary 32bits application
Hi,
If I understand you correctly, and you want a separate per process page directory, you need to do the following:
1. Create and zero a new page directory (0x1000 aligned) somewhere.
2. Create and zero a new page table - pass the physical address of this and any flags to Pade_Dir[0], eg:
3. Allocate physical RAM for your new process and pass this address to your first PTE in the same way. In your case, this will be:
4. I would advise loading one of the 4MB ranges in your PD as itself. For example:
This will allow the easy addition of later mappings in to this address space.
5. When you are ready to switch address space, load CR3 with the physical page directory location.
If you do not want separate process spaces, you would do the same but ignore step 1.
I'm not quite sure what all the bit shifting is about in your code, but I may be missing something.
Cheers,
Adam
If I understand you correctly, and you want a separate per process page directory, you need to do the following:
1. Create and zero a new page directory (0x1000 aligned) somewhere.
2. Create and zero a new page table - pass the physical address of this and any flags to Pade_Dir[0], eg:
Code: Select all
PD[0] = pt | PAGE_PRESENT | PAGE_WRITE | PAGE_USER;
Code: Select all
PT[0] = 0x131000 | PAGE_PRESENT | PAGE_WRITE | PAGE_USER;
Code: Select all
PD[0x3FF] = physical_pd_address | PAGE_PRESENT | PAGE_WRITE;
5. When you are ready to switch address space, load CR3 with the physical page directory location.
If you do not want separate process spaces, you would do the same but ignore step 1.
I'm not quite sure what all the bit shifting is about in your code, but I may be missing something.
Cheers,
Adam
Code: Select all
unsigned int *page_table = (unsigned int *)page_dir[0] & 0xFFF;
page_table[0] = physical_address | 0x1 /* present */ | 0x2 /* writeable */ | 0x4 /* user-mode */;
* The executable is < 4KB in size.
* physical_address is set to the physical position you load your file to (e.g. 0x131000).
EDIT: Damn yer eyes AJ! Posted < 1 minute before me!