[Gems-users] Re: The process to get pid and related questions


Date: Fri, 3 Jun 2005 14:33:21 -0400
From: Weihang Jiang <weihang.jiang@xxxxxxxxx>
Subject: [Gems-users] Re: The process to get pid and related questions
Sorry I forgot to attach it.  Here is the assembly code of "reume".

resume:                         save      %sp, -0xb0, %sp
resume+4:                       membar    #Sync
resume+8:                       flushw
resume+0xc:                     stx       %i7, [%g7 + 0x38]
resume+0x10:                    stx       %fp, [%g7 + 0x40]
resume+0x14:                    ldx       [%g7 + 0x110], %o4
resume+0x18:                    rd        %fprs, %g4
resume+0x1c:                    brnz,pt   %o4, +0x34    <resume+0x50>
resume+0x20:                    ldx       [%g7 + 0xa8], %i1
resume+0x24:                    ldx       [%g7 + 8], %i2
resume+0x28:                    ldx       [%g7 + 0x78], %g3
resume+0x2c:                    btst      4, %g4
resume+0x30:                    be,pt     %icc,+0x48    <resume+0x78>
resume+0x34:                    st        %g4, [%i2 + 0x1b8]
resume+0x38:                    add       %i2, 0xb0, %o0
resume+0x3c:                    rd        %gsr, %g5
resume+0x40:                    call      -0xe740       <fp_fksave>
resume+0x44:                    stx       %g5, [%o0 + 0x120]
resume+0x48:                    ba,a,pt   %icc,+0x30    <resume+0x78>
resume+0x4c:                    nop
resume+0x50:                    ldx       [%o4 + 0x100], %o0
resume+0x54:                    stx       %fp, [%g7 + 0x40]
resume+0x58:                    btst      4, %g4
resume+0x5c:                    st        %g4, [%o0 + 0x108]
resume+0x60:                    be,pt     %icc,+0x18    <resume+0x78>
resume+0x64:                    ldx       [%g7 + 0x78], %g3
resume+0x68:                    ldx       [%o4 + 0x100], %o0
resume+0x6c:                    rd        %gsr, %g5
resume+0x70:                    call      -0xe770       <fp_fksave>
resume+0x74:                    stx       %g5, [%o0 + 0x120]
resume+0x78:                    mov       %g0, %fprs
resume+0x7c:                    brz,pt    %g3, +0x10    <resume+0x8c>
resume+0x80:                    ldx       [%i0 + 0x118], %i3
resume+0x84:                    call      +0x10fda0     <savectx>
resume+0x88:                    mov       %g7, %o0
resume+0x8c:                    ldx       [%g7 + 0x118], %i2
resume+0x90:                    ldx       [%i1 + 0x18], %o0
resume+0x94:                    ldx       [%o0 + 0x40], %o1
resume+0x98:                    sub       %o1, 0xb0, %sp
resume+0x9c:                    clr       %fp
resume+0xa0:                    mov       %g7, %l3
resume+0xa4:                    mov       %o0, %g7
resume+0xa8:                    stx       %o0, [%i1 + 0x10]
resume+0xac:                    clrb      [%l3 + 0xa0]

I am running solaris 9

in opal/system/pseq.C, there is
"
// dereference virtual addresses plus offset (Solaris 9)
la_t procp    = M_PSTATE->dereference( thread_p + 0x110, 8 );
la_t pidp     = M_PSTATE->dereference( procp + 0xb0, 8 );
int32 pid     = M_PSTATE->dereference( pidp + 0x4, 4 );
#if 0
  // Solaris 8
  la_t procp    = M_PSTATE->dereference( thread + 0x130, 8 );
  la_t pidp     = M_PSTATE->dereference( procp + 0xb0, 8 );
  int32 pid     = M_PSTATE->dereference( pidp + 0x4, 4 );
#endif
"
In step 6, I try both
@thread = SIM_read_phys_memory(conf.cpu0, 0x3000010,8)
@procp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,thread+0x110),8)
                                                                                                                                                        ^^^^^
@pidp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,procp+0xb0),8)
@pid= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,pidp+0x4),4)
@print pid
and
@thread = SIM_read_phys_memory(conf.cpu0, 0x3000010,8)
@procp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,thread+0x130),8)
                                                                                                                                                       ^^^^^^
@pidp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,procp+0xb0),8)
@pid= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0,Sim_DI_Data,pidp+0x4),4)
@print pid

Using "0x110" offset, I always receive following errero message :
Traceback (most recent call last):
  File "<string>", line 1, in ?
sim_core.SimExc_Memory: No translation
If using "0x130" offset, as I mentioned, the value of pid is always equal to 1.

Thanks

Weihang

On 6/3/05, Min Xu (Hsu) <xu@xxxxxxxxxxx> wrote:
Weihang,

I am not sure I fully grasped the problem. Where is your attachment?

I wonder whether you are getting the right kernel variable for PID. Do you have
the source code for the kernel version you are running? It is possible the
kernel code changes from version to version.

Please provide more information.

Thanks!

-Min

On Fri, 03 Jun 2005 Weihang Jiang wrote :
> The process to get pid from inside simulator:
>
> 1. find the break address using mdb in the simulation machine
> mdb -k
> 2. find the instruction that modified the pid "stx ... [%l0 + 0x10]"
> >::dis resume (see attachment)
> can't not find "stx ... [%l0 + 0x10]", instead, I pick "resume+0xa8: stx
> %o0, [%i1 + 0x10]"
> 3. find the starting address of the function "resume"
> > resume=X
> 102da90
> now the starting address of resume + offset is the break point = 0x102da90 +
> 0xa8 = 0x102db38
> 4. ./simics -c xxx.check
> break 0x102db38
> c
> @cpu = SIM_current_processor()
> @cwp = SIM_read_register(cpu, SIM_get_register_number(cpu, "cwp"))
> @va = SIM_get_interface(cpu, "sparc-v9").read_window_register(cpu, cwp, 25)
> + 0x10
> @pa = SIM_logical_to_physical(cpu, Sim_DI_Data, va)
> @print pa
> output: 50331664 (0x3000010 ) (this is thread_physical_addr)
>
> 5. @SIM_breakpoint(SIM_get_object
> ("phys_mem0"),Sim_Break_Physical,Sim_Access_Write,0x3000010,4,0)
> c
>
> 6. @thread = SIM_read_phys_memory(conf.cpu0, 0x3000010,8)
> (thread = 2890513120576)
> @procp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0
> ,Sim_DI_Data,thread+0x130),8)
> (procp = 21012480)
> @pidp= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical(conf.cpu0
> ,Sim_DI_Data,procp+0xb0),8)
> (pidp = 21451608)
> @pid= SIM_read_phys_memory(conf.cpu0, SIM_logical_to_physical( conf.cpu0
> ,Sim_DI_Data,pidp+0x4),4)
> (pid = 1)
>
> The problem is that the pid is always equal to "1" (never changed). Can
> anyone point out where I made mistake?
>
> --
> Weihang Jiang



--
Weihang Jiang
[← Prev in Thread] Current Thread [Next in Thread→]