ppc manual paging question
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · Baojun
hi,
I've got some qeustion about ppc(ppc44x) paging:
Quoted 8 lines
how can I manually map a virtual address to a physical address through a specific pgd? How does ppc translate virt address to physical one? I think besides from tlb, the CPU will search the page table entries via the pgd, can I alter the pgd value to change the memory translation? under i386, it's very simple, we can just rewrite %%cr3, it even could invalidate all tlb entries automatically, how can I do this under ppc? I've tried rewrite
current->mm->pgdandcurrent->thread.pgdir, but sounds like it still not insufficiant, am I missing something vital?
What the heck are you trying to do ? Please explain and I'll tell you how to do it properly :-)
Cheers,
Ben.
A message that is not in the archive (sent off-list or not yet received): [email protected]
On Monday 22 October 2007 12:50:52, Benjamin Herrenschmidt wrote=EF=BC=9A
Quoted 15 lines · Baojun
Quoted 4 lines
hi,
I've got some qeustion about ppc(ppc44x) paging:
Quoted 9 lines
how can I manually map a virtual address to a physical address through a specific pgd? How does ppc translate virt address to physical one? I think besides from tlb, the CPU will search the page table entries via the pgd, can I alter the pgd value to change the memory translation? under i386, it's very simple, we can just rewrite %%cr3, it even could invalidate all tlb entries automatically, how can I do this under ppc? I've tried rewrite
current->mm->pgdandcurrent->thread.pgdir, but sounds like it still not insufficiant, am I missing something vital?
Quoted 2 lines
What the heck are you trying to do ? Please explain and I'll tell you how to do it properly :-)
I'm porting an adeos nano kernel named xtratum (http://www.xtratum.org) fro= m=20
x86 to ppc, I think I'm near the ending except the above problem. xtratum i= s=20
doing things like xen but it's much simpler (it's aimed for realtime), it=20 need provides memory space sperations for it's domains, so I need manually= =20
paging. Each domain is loaded by a userspace program (instead of the root=20 domain as a kernel module), the loader will load the domain's (ELF staticly= =20
excutable) PT_LOAD section into memory, and then raise a properly system ca= ll=20
(passing the structurized loaded data as arguments) to load the domain via= =20load_domain_sys(), and at the last step of loading the domain, xtratum will= =20
jump to the entry code of the new domain(asm wrappered start() routine) and= =20
then everything should be fine. The problem now is as follow:
under my ppc (440GR/440EP) platform, start() is always at 0x100000a0, but I= =20
guess there is something wrong with my mm code so after the domain is loade= d,=20
the virt addres 0x100000a0 just point to garbage instead of the right start= ()=20
routine. So how can I setup paging properly so that the virtual memory coul= d=20
be translated to proper data?
I can describe in more detail if neccessary.
Thanks very much for take care.
Regards,
Wang
P.S:
The orignal xtratum (x86) code:
#define load_pd(pd) {\
__asm__ __volatile__ ("movl %0,%%cr3": :"r" (__pa(pd))); \
}
#define save_pd(pd) {\
__asm__ __volatile__ ("movl %%cr3, %0\n\t": "=3Dr" (pd) :); \
pd =3D (unsigned long) __va (pd); \
}
=2E..
// Virtual address to page directory entry #define va2pd(vaddress) ((vaddress) >> PGDIR_SHIFT)
// Virtual address to page table entry
#define va2pt(vaddress) (((vaddress) & 0x3FF000) >> PAGE_SHIFT)
// Page directory and page table to virtual address
#define pdpt2va(pd, pt) (((pd) << PGDIR_SHIFT) | ((pt) << PAGE_SHIFT))
// Next macro allows to obtain a pt address through the page directory #define get_pd_addr(pd, pd_entry) \
((unsigned long) __va (((unsigned long *)(pd)) [(pd_entry)] & PAGE_MASK))
// And the following one allows to obtain a page address via the page // table
#define get_pt_addr(pt, pt_entry) \
((unsigned long)__va (((unsigned long *)*(pt)) [(pt_entry)] & PAGE_MASK))
=2E..
static inline void fill_pd_entry (unsigned long pd,
unsigned long pd_entry, unsigned long pt, unsigned long flags) {
((unsigned long *)pd) [pd_entry] =3D
((__pa (pt) & PAGE_MASK) | (flags & 0xFFF)); }
static inline void fill_pt_entry (unsigned long pt,
unsigned long pt_entry, unsigned long page, unsigned long flags) {
((unsigned long *)pt) [pt_entry] =3D
((__pa (page) & PAGE_MASK) | (flags & 0xFFF)); }
=2E..
static inline unsigned long create_page_directory (unsigned long
(*alloc_page) (void)) { unsigned long pd =3D (*alloc_page) (), c_pd;
if (!pd) return pd; save_pd(c_pd);
memset ((unsigned char *) &((unsigned long *) pd)[0],
0, 1024 * sizeof (unsigned long));
memcpy ((unsigned char *) &((unsigned long *) pd)[va2pd(PAGE_OFFSET)],
(unsigned char *) &((unsigned long *) c_pd)[va2pd(PAGE_OFFSET)],
(1024 - va2pd(PAGE_OFFSET)) * sizeof (unsigned long)); return pd;
}
static inline unsigned long allocate_user_page (unsigned long pd,
unsigned long vaddress, unsigned long (*alloc_page) (void)) {
unsigned long pt_entry =3D va2pt(vaddress),
pd_entry =3D va2pd(vaddress), pt, page =3D 0;
if (vaddress >=3D PAGE_OFFSET) return 0;
// Check if there is already an allocated pt in the pd table
if (!(((unsigned long *)pd) [pd_entry] & _PAGE_PRESENT)) {
if (!(pt =3D (unsigned long) (*alloc_page) ())) return 0;
fill_pd_entry (pd, pd_entry,
pt, _PAGE_PRESENT | _PAGE_RW | _PAGE_USER);
} else
pt =3D get_pd_addr(pd, pd_entry);// Check whether there is already an allocated page in the pt table
if (!(((unsigned long *)pt)[pt_entry] & _PAGE_PRESENT)) {
if (!(page =3D (unsigned long) (*alloc_page) ())) return 0;
fill_pt_entry (pt, pt_entry, page,
_PAGE_PRESENT | _PAGE_RW | _PAGE_USER); }
return page;
}
Quoted 2 lines
Cheers,
Ben.
=2D-=20
Wang, Baojun =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0Lanzhou University
Distributed & Embedded System Lab =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0http://dslab.lzu.edu.cn
School of Information Science and Engeneering =C2=A0 =C2=A0 =C2=A0 =C2=A0wa= [email protected]
Tianshui South Road 222. Lanzhou 730000 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .P.R.China Tel:+86-931-8912025 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Fax:+86-931-8912022
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 13 lines
I'm porting an adeos nano kernel named xtratum (http://www.xtratum.org) from x86 to ppc, I think I'm near the ending except the above problem. xtratum is doing things like xen but it's much simpler (it's aimed for realtime), it need provides memory space sperations for it's domains, so I need manually paging. Each domain is loaded by a userspace program (instead of the root domain as a kernel module), the loader will load the domain's (ELF staticly excutable)
PT_LOADsection into memory, and then raise a properly system call (passing the structurized loaded data as arguments) to load the domain viaload_domain_sys(), and at the last step of loading the domain, xtratum will jump to the entry code of the new domain(asm wrapperedstart()routine) and then everything should be fine. The problem now is as follow:
Quoted 5 lines
under my ppc (440GR/440EP) platform,
start()is always at0x100000a0, but I guess there is something wrong with my mm code so after the domain is loaded, the virt addres0x100000a0just point to garbage instead of the rightstart()routine. So how can I setup paging properly so that the virtual memory could be translated to proper data?
Are you aware that the 440 MMU doesn't actually know what a page table is and doesn't load PTEs from memory ?
It's a software loaded TLB, you'll have to put translations in the TLB yourself. You'll need to design your own data structures for that, tho you can use a page table for tracking, like we do in linux, and then have your own TLB miss handler to fill the TLB from that.
Your initial code probably need to bolt a TLB entry for the kernel itself.
Ben.
A message that is not in the archive (sent off-list or not yet received): [email protected]
On Monday 22 October 2007 14:01:33, Benjamin Herrenschmidt wrote=EF=BC=9A
Quoted 6 lines
Quoted 6 lines
I'm porting an adeos nano kernel named xtratum (http://www.xtratum.org)
from x86 to ppc, I think I'm near the ending except the above problem. xtratum is doing things like xen but it's much simpler (it's aimed for realtime), it need provides memory space sperations for it's domains, so I need manually paging. Each domain is loaded by a userspace program (instead of the root domain as a kernel module), the loader will load t=
he
Quoted 3 lines
Quoted 3 lines
domain's (ELF staticly excutable)
PT_LOADsection into memory, and then raise a properly system call (passing the structurized loaded data as arguments) to load the domain viaload_domain_sys(), and at the last st=
ep
Quoted 2 lines
Quoted 2 lines
of loading the domain, xtratum will jump to the entry code of the new domain(asm wrappered
start()routine) and then everything should be fin=
e.
Quoted 3 lines
Quoted 3 lines
The problem now is as follow:
under my ppc (440GR/440EP) platform,
start()is always at0x100000a0, b=
ut
Quoted 7 lines
Quoted 4 lines
I guess there is something wrong with my mm code so after the domain is loaded, the virt addres
0x100000a0just point to garbage instead of the rightstart()routine. So how can I setup paging properly so that the virtual memory could be translated to proper data?Are you aware that the 440 MMU doesn't actually know what a page table is and doesn't load PTEs from memory ?
Sorry I didn't realized that. I've finished looking pem64b.pdf, but it's=20 almost nothing like in ppc 4xx/44x.
Quoted 4 lines
It's a software loaded TLB, you'll have to put translations in the TLB yourself. You'll need to design your own data structures for that, tho you can use a page table for tracking, like we do in linux, and then have your own TLB miss handler to fill the TLB from that.
OK, Shall I look for the DataTLBError code in head.S? I realized that I've = got=20
DataTLBError sometimes via BDI2000/kgdb (the fault address is within=20 DataTLBError), Shall I should also look for arch/ppc/mm/fault.c?
Quoted 2 lines
Your initial code probably need to bolt a TLB entry for the kernel itself.
I don't understand this clearly, how can I do this?
Quoted 1 line
Ben.
Regards,
Wang
=2D-=20
Wang, Baojun =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0Lanzhou University
Distributed & Embedded System Lab =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0http://dslab.lzu.edu.cn
School of Information Science and Engeneering =C2=A0 =C2=A0 =C2=A0 =C2=A0wa= [email protected]
Tianshui South Road 222. Lanzhou 730000 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .P.R.China Tel:+86-931-8912025 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Fax:+86-931-8912022
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 4 lines
OK, Shall I look for the DataTLBError code in
head.S? I realized that I've got DataTLBError sometimes via BDI2000/kgdb (the fault address is within DataTLBError), Shall I should also look forarch/ppc/mm/fault.c?
if you end up in fault.c (via call to handle_page_fault) then I think you allready had an invalid access - you should not have ended there if the tlb entries would have been loaded properly from where ever XM put them (not in any pgd that linux knows of) - no COW or lazy mechanism available
as the pgd of the domains are not handled in fault.c .
hofrat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFHHFcZnU7rXZKfY2oRAtKLAJ4pdGYGSrv/WFEraJiiHdeGndVupwCgiz56 Le5QyhS1dpfdgb0pbe5hLRk=
=PutX
-----END PGP SIGNATURE-----
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines
Sorry I didn't realized that. I've finished looking pem64b.pdf, but it's almost nothing like in ppc 4xx/44x.
You'll have to get yourself a 44x manual :-)
Quoted 8 lines
Quoted 4 lines
It's a software loaded TLB, you'll have to put translations in the TLB yourself. You'll need to design your own data structures for that, tho you can use a page table for tracking, like we do in linux, and then have your own TLB miss handler to fill the TLB from that.
OK, Shall I look for the DataTLBError code in
head.S? I realized that I've got DataTLBError sometimes via BDI2000/kgdb (the fault address is within DataTLBError), Shall I should also look forarch/ppc/mm/fault.c?
head_44x.S is where you'll find some guidance
Quoted 3 lines
Quoted 2 lines
Your initial code probably need to bolt a TLB entry for the kernel itself.
I don't understand this clearly, how can I do this?
Well, you insert a TLB entry manually and avoid replacing it later on
Ben.
A message that is not in the archive (sent off-list or not yet received): [email protected]
On Monday 22 October 2007 15:34:24, Benjamin Herrenschmidt wrote:
Quoted 10 lines
Quoted 2 lines
Sorry I didn't realized that. I've finished looking pem64b.pdf, but it's almost nothing like in ppc 4xx/44x.
You'll have to get yourself a 44x manual :-)
Quoted 5 lines
Quoted 4 lines
It's a software loaded TLB, you'll have to put translations in the TLB yourself. You'll need to design your own data structures for that, tho you can use a page table for tracking, like we do in linux, and then have your own TLB miss handler to fill the TLB from that.
Quoted 5 lines
Quoted 3 lines
OK, Shall I look for the DataTLBError code in
head.S? I realized that I've got DataTLBError sometimes via BDI2000/kgdb (the fault address is within DataTLBError), Shall I should also look forarch/ppc/mm/fault.c?
head_44x.Sis where you'll find some guidance
Yup, I've found how does the kernel handle tlbs, I think the most important thing is I forgot read/write the SPRN_SPRG3 register as _switch does.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Your initial code probably need to bolt a TLB entry for the kernel itself.
I don't understand this clearly, how can I do this?
Well, you insert a TLB entry manually and avoid replacing it later on
I've add the _PAGE_PRESENT flag to the related PTE
Quoted 1 line
Ben.
Thanks very much I'm now getting much clearer about my question:)
Regards,
Wang
Signature · 5 lines
Wang, Baojun Lanzhou University Distributed & Embedded System Lab http://dslab.lzu.edu.cn School of Information Science and Engeneering [email protected] Tianshui South Road 222. Lanzhou 730000 .P.R.China Tel:+86-931-8912025 Fax:+86-931-8912022
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines
Yup, I've found how does the kernel handle tlbs, I think the most important thing is I forgot read/write the
SPRN_SPRG3register as_switchdoes.
SPRG3 is for use by the operating system for whatever you want... if you are copying linux code, then you probably indeed want to get that right but you don't have to use SPRG3.
Quoted 1 line
I've add the
_PAGE_PRESENTflag to the related PTE
Hrm.. that has nothing ot do with the PTE. Bolting is more a property of your replacement algorithm in the TLB miss handler.
Ben.
A message that is not in the archive (sent off-list or not yet received): [email protected]
On Monday 22 October 2007 16:04:14, Benjamin Herrenschmidt wrote:
Quoted 8 lines
Quoted 3 lines
Yup, I've found how does the kernel handle tlbs, I think the most important thing is I forgot read/write the
SPRN_SPRG3register as_switchdoes.SPRG3 is for use by the operating system for whatever you want... if you are copying linux code, then you probably indeed want to get that right but you don't have to use SPRG3.
Quoted 6 lines
Quoted 1 line
I've add the
_PAGE_PRESENTflag to the related PTEHrm.. that has nothing ot do with the PTE. Bolting is more a property of your replacement algorithm in the TLB miss handler.
Ben.
Hi,
First thanks a lot for your help I've finish the tlb code, now I can
manually translate the virtual address correctly, I verified this by printing out the data within the virtual address and it's fine. now the only thing left is jump to that address (the address is point to _start function), But I got an error about unable to access the stack (0xd100fc60 ...), but it is valid before the instruction:
/**
* XXX: should not defined here
*/
#define EVENTS_USER_ADDR_OFFSET 36
_GLOBAL(jump_xm_dom)
stwu r1,-INT_FRAME_SIZE(r1)
mflr r0
stw r0,INT_FRAME_SIZE+4(r1) stw r31,INT_FRAME_SIZE+128(r1)
lwz r5,EVENTS_USER_ADDR_OFFSET(r4)
mr r31,r5 /* new_domain->events_user_addr */
cmpwi r3,0
beq 1f
mtctr r3 /* jump to entry_point */
bctrl
li r3,0
1:
lwz r31,INT_FRAME_SIZE+128(r1)
lwz r0,INT_FRAME_SIZE+4(r1)
addi r1,r1,INT_FRAME_SIZE
mtlr r0
blrthe SP is valid before `bctrl', while exec bctrl, I got the error said unable to access address SP ($r1) from bdigdb, without bdigbd (running directly), an error is print out while the system is dead:
insn: 94 21 ff 40 7c 08 02 a6 90 01 00 c4 7f e3 fb 78 3d 20 10 01 90 69 07 a0 48 00 02 55 80 01 00 c4
$T0440:10000094;01:d1072e60;#ee
address d1072e60 is the address of SP ($r1) before bctrl.
NOTE entry_point($r3) is address like 0x100000a0 which is loaded from the userspace by a loader program (it loads all section marked as PT_LOAD, such as .text, the above insn is the entry of .text section, which is _start), but the above code is from the kernel space. and here is the _start function:
#define INT_FRAME_SIZE 192
.globl _start_start:
stwu 1, -INT_FRAME_SIZE(1)
mflr 0
stw 0, INT_FRAME_SIZE+4(1) mr 3,31 /* new_domain->events_user_addr */
lis 9, event_handling@ha
stw 3, event_handling@l(9)
bl kmain
lwz 0, INT_FRAME_SIZE+4(1);
mtlr 0
addi 1, 1, INT_FRAME_SIZE
blr
.size _start, .-_start
I'm sorry I'm not very familiar with the ppc assembly, is there something fundamentally wrong? Thank you very much!
Regards,
Wang
Signature · 5 lines
Wang, Baojun Lanzhou University Distributed & Embedded System Lab http://dslab.lzu.edu.cn School of Information Science and Engeneering [email protected] Tianshui South Road 222. Lanzhou 730000 .P.R.China Tel:+86-931-8912025 Fax:+86-931-8912022