Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PPC 8260 - reading program counter

832 views
Skip to first unread message

Derek Opitz

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to
How do I read the program counter?

Writing exceptions for the 8260, and I want access to the program counter.
I think I can get access to all other registers, but I don't know how to get
access to the program counter.

Thanks in advance,

Derek

Doug Gibbons

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to

There is no pc register. When handling an exception you can examine SRR0 to
determine the source of the exception. To get hold of a current pc value
you can play games with the branch and link instructions (branch to next
address) so that the LR is filled with the next pc.

--
--------------------------------------------------------------------------------
Lee Douglas Gibbons
ldgi...@avaya.com

Derek Opitz

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to
Appreciate the info...

Doug Gibbons <ldgi...@avaya.com> wrote in message
news:3A26AC96...@avaya.com...

Fredrik Andersson

unread,
Dec 3, 2000, 1:36:37 AM12/3/00
to

> There is no pc register.

There is a pc register, although it's not accessable (the ways to findout / modify
the pc is either by
changing srr0 or lr as you said, however when changing lr keep in mind that you
need to back up
the old lr or you'll easially get caugth in a loop).

However here's a little snippet I used for a little program...

asm long getpc()
{
mflr r4;
bl a:
mflr r3;
mtlr r4;
a: blr
}

something like this works pretty good for system level code, although, you need to
make sure
that this function gets inlined otherwise it will return the same pc eachtime you
call it.

/Fredrik Andersson

Kenneth C. Dyke

unread,
Dec 3, 2000, 3:00:00 AM12/3/00
to
On 12/02/00, Fredrik Andersson wrote:
>
>
>> There is no pc register.
>
>There is a pc register, although it's not accessable (the ways to
findout / modify
>the pc is either by
>changing srr0 or lr as you said, however when changing lr keep in mind
that you
>need to back up
>the old lr or you'll easially get caugth in a loop).
>
>However here's a little snippet I used for a little program...
>
>asm long getpc()
>{
> mflr r4;
> bl a:
> mflr r3;
> mtlr r4;
>a: blr
>}

Shouldn't that be:


asm long getpc()
{
mflr r4;
bl a:
a: mflr r3;
mtlr r4;

blr
}


--
Kenneth Dyke, k...@jumpgate.com (personal), kd...@apple.com (work)
Sr. Mad Scientist, MacOS X OpenGL Group, Apple Computer, Inc.
C++: The power, elegance and simplicity of a hand grenade.


Fredrik Andersson

unread,
Dec 3, 2000, 3:00:00 AM12/3/00
to

"Kenneth C. Dyke" wrote:

> >asm long getpc()
> >{
> > mflr r4;
> > bl a:
> > mflr r3;
> > mtlr r4;
> >a: blr
> >}
>

> Shouldn't that be:


> asm long getpc()
> {
> mflr r4;
> bl a:
> a: mflr r3;
> mtlr r4;

> blr
> }

right, I didn't notice this, although both works except that the first
verison takes slightly longer.
(however it was ment to look as your version does)

/Fredrik Andersson

Derek Opitz

unread,
Dec 4, 2000, 3:00:00 AM12/4/00
to
thanks guys

Fredrik Andersson <an...@digithought.net> wrote in message
news:3A2A62E2...@digithought.net...


>
>
> "Kenneth C. Dyke" wrote:
>
> > >asm long getpc()
> > >{
> > > mflr r4;
> > > bl a:
> > > mflr r3;
> > > mtlr r4;
> > >a: blr
> > >}
> >

> > Shouldn't that be:


> > asm long getpc()
> > {
> > mflr r4;
> > bl a:
> > a: mflr r3;
> > mtlr r4;

Andrew Klossner

unread,
Dec 7, 2000, 3:00:00 AM12/7/00
to
> The problem is that I now want to run this on Mac OS X and the code
> space is read only. Now I know I can set up data space in the
> assembler code, but the real question is can I then execute the code
> I write into the data space?

That's a Macintosh question, not a PowerPC question. Ask in a Mac
newsgroup whether OS X can enable instruction fetches from data
segments.

-=- Andrew Klossner (and...@teleport.com)

Pete Hoch

unread,
Dec 7, 2000, 3:00:00 AM12/7/00
to

So sorry, I looked over some messages here and saw the Mac mentioned and PPC
assembler. I figured someone here may know. I didn't mean to intrude on
your club.

Pete


Tony Nelson

unread,
Dec 7, 2000, 3:00:00 AM12/7/00
to
In article <B6553591.11BFF%pho...@rochester.rr.com>, Pete Hoch
<pho...@rochester.rr.com> wrote:

> I am working on porting some old code from the current Macintosh OS
> to OS X. It is a very big project and at the heart of it is a bunch
> of assembler code that is self modifying. ...

> The problem is that I now want to run this on Mac OS X and the code
> space is read only. Now I know I can set up data space in the
> assembler code, but the real question is can I then execute the code

> I write into the data space? Any suggestions or pointers would be
> helpful. I can send some code snippets if that helps.

I don't know the answer, but is MakeDataExecutable() available in
Carbon? Perhaps someone knows on c.s.m.p.h.
____________________________________________________________________
TonyN.:' tony...@shore.net
'

Pete Hoch

unread,
Dec 7, 2000, 12:32:07 PM12/7/00
to
Hi all,

I am working on porting some old code from the current Macintosh OS to OS X.
It is a very big project and at the heart of it is a bunch of assembler code

that is self modifying. The code is used to analyze data in real time and
so the programmer put together a little internal compiler which uses little
code templates, modifies them, and then writes them out to the middle of an
existing routine. This was all done over 10 years ago, first on 68K and
them PPC assembler and all of the original programmers are gone.

The problem is that I now want to run this on Mac OS X and the code space is
read only. Now I know I can set up data space in the assembler code, but
the real question is can I then execute the code I write into the data
space? Any suggestions or pointers would be helpful. I can send some code
snippets if that helps.

Pete

Pete Hoch

unread,
Dec 8, 2000, 3:00:00 AM12/8/00
to
> From: Tony Nelson <tony...@shore.net>

>> The problem is that I now want to run this on Mac OS X and the code
>> space is read only. Now I know I can set up data space in the
>> assembler code, but the real question is can I then execute the code
>> I write into the data space? Any suggestions or pointers would be
>> helpful. I can send some code snippets if that helps.

> I don't know the answer, but is MakeDataExecutable() available in


> Carbon? Perhaps someone knows on c.s.m.p.h.

I just looked it up, and yes it is in Carbon. Thanks this is just the
pointer I needed.

Pete


shakti....@gmail.com

unread,
Mar 2, 2015, 5:54:02 AM3/2/15
to
On Thursday, 30 November 2000 13:30:00 UTC+5:30, Derek Opitz wrote:
> How do I read the program counter?
>
> Writing exceptions for the 8260, and I want access to the program counter.
> I think I can get access to all other registers, but I don't know how to get
> access to the program counter.
>
> Thanks in advance,
>
> Derek

Hi,
My problem is related to PPC crash handler. I had implemented crash handler in arm but when I am trying to implement crash handler in PPC, I am facing some problem. In arm registers we use pc (program counter), frame pointer (fp) and sp(stack pointer). BUT when I trying to implement crash handler in PPC, registers name are different like general purpose register (gpr), floating point register(fpr),srr0, lr.
Which register in PPC, I should use as pc, which register should I use as fp and which register should I use as pc.
Please help me.

Regards,
Shakati
0 new messages