summaryrefslogtreecommitdiff
path: root/sys/src/libc/port/profile.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-02-17 13:25:24 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2014-02-17 13:25:24 +0100
commit2c5c78425516590e894c9c334182073fcc56a10b (patch)
treeec4c8b58ec1d8144936bf8111382a6e7141d55c0 /sys/src/libc/port/profile.c
parent87fcb107ef333f5dce7618e0f4c73d69ebc75eb5 (diff)
prof: properly save and restore RARG for amd64
amd64 passes first argument in RARG (BP) register which has the be preserved duing _profin() and _profout() calls. to handle this we introduce _saveret() and _savearg(). _saveret() returns AX, _savearg() returns RARG (BP). for archs other and amd64, _saveret() and _savearg() are the same function, doing nothing. restoing works with dummy function: uintptr _restore(uintptr, uintptr ret) { return ret; } ... ret = _saveret(); arg = _savearg(); ... return _restore(arg, ret); as we pass arg as the first argument, RARG (BP) is restored.
Diffstat (limited to 'sys/src/libc/port/profile.c')
-rw-r--r--sys/src/libc/port/profile.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/sys/src/libc/port/profile.c b/sys/src/libc/port/profile.c
index 5647e3bf1..b1eb0afaa 100644
--- a/sys/src/libc/port/profile.c
+++ b/sys/src/libc/port/profile.c
@@ -2,8 +2,9 @@
#include <libc.h>
#include <tos.h>
-extern long _callpc(void**);
-extern long _savearg(void);
+extern uintptr _callpc(void**);
+extern uintptr _saveret(void);
+extern uintptr _savearg(void);
static ulong khz;
static ulong perr;
@@ -22,21 +23,27 @@ struct Plink
#pragma profile off
-ulong
+static uintptr
+_restore(uintptr, uintptr ret)
+{
+ return ret;
+}
+
+uintptr
_profin(void)
{
void *dummy;
long pc;
Plink *pp, *p;
- ulong arg;
+ uintptr arg, ret;
vlong t;
+ ret = _saveret();
arg = _savearg();
pc = _callpc(&dummy);
pp = _tos->prof.pp;
if(pp == 0 || (_tos->prof.pid && _tos->pid != _tos->prof.pid))
- return arg;
-
+ return _restore(arg, ret);
for(p=pp->down; p; p=p->link)
if(p->pc == pc)
goto out;
@@ -44,7 +51,7 @@ _profin(void)
if(p >= _tos->prof.last) {
_tos->prof.pp = 0;
perr++;
- return arg;
+ return _restore(arg, ret);
}
_tos->prof.next = p;
p->link = pp->down;
@@ -75,20 +82,21 @@ out:
p->time = p->time - _tos->clock;
break;
}
- return arg; /* disgusting linkage */
+ return _restore(arg, ret);
}
-ulong
+uintptr
_profout(void)
{
Plink *p;
- ulong arg;
+ uintptr ret, arg;
vlong t;
+ ret = _saveret();
arg = _savearg();
p = _tos->prof.pp;
if (p == nil || (_tos->prof.pid != 0 && _tos->pid != _tos->prof.pid))
- return arg; /* Not our process */
+ return _restore(arg, ret); /* Not our process */
switch(_tos->prof.what){
case Profkernel: /* Add proc cycles on proc entry */
p->time = p->time + _tos->pcycles;
@@ -106,7 +114,7 @@ _profout(void)
break;
}
_tos->prof.pp = p->old;
- return arg;
+ return _restore(arg, ret);
}
void