/* subr_prof.c 4.1 82/06/28 */
* Froms is actually a bunch of unsigned shorts indexing tos
struct tostruct
*tos
= 0;
char *s_lowpc
= (char *)0x80000000;
s_textsize
= s_highpc
- s_lowpc
;
ssiz
= s_textsize
+ sizeof(struct phdr
);
printf("Profiling kernel, s_textsize=%d [%x..%x]\n",
s_textsize
, s_lowpc
, s_highpc
);
sbuf
= (u_short
*)wmemall(vmemall
, ssiz
);
printf("No space for monitor buffer(s)\n");
blkclr((caddr_t
)sbuf
, ssiz
);
froms
= (u_short
*)wmemall(vmemall
, s_textsize
);
printf("No space for monitor buffer(s)\n");
blkclr((caddr_t
)froms
, s_textsize
);
tos
= (struct tostruct
*)wmemall(vmemall
, s_textsize
);
printf("No space for monitor buffer(s)\n");
wmemfree(froms
, s_textsize
);
blkclr((caddr_t
)tos
, s_textsize
);
limit
= s_textsize
/ sizeof(struct tostruct
);
* Tolimit is what mcount checks to see if
* all the data structures are ready!!!
* Make sure it won't overflow.
tolimit
= limit
> 65534 ? 65534 : limit
;
((struct phdr
*)sbuf
)->lpc
= s_lowpc
;
((struct phdr
*)sbuf
)->hpc
= s_highpc
;
((struct phdr
*)sbuf
)->ncnt
= ssiz
;
kcount
= (u_short
*)(((int)sbuf
) + sizeof(struct phdr
));
profiling
= 0; /* patch by hand when you're ready */
* This routine is massaged so that it may be jsb'ed to
asm("#define _mcount mcount");
register char *selfpc
; /* r11 */
register u_short
*frompcindex
; /* r10 */
register struct tostruct
*top
; /* r9 */
asm(" forgot to run ex script on gcrt0.s");
* Find the return address for mcount,
* and the return address for mcount's caller.
asm(" movl (sp), r11"); /* selfpc = ... (jsb frame) */
asm(" movl 16(fp), r10"); /* frompcindex = (calls frame) */
* Check that we are profiling
* and that we aren't recursively invoked.
* Check that frompcindex is a reasonable pc value.
* For example: signal catchers get called from the stack,
* not from text space. too bad.
frompcindex
= (u_short
*)((long)frompcindex
- (long)s_lowpc
);
if ((u_long
)frompcindex
> s_textsize
)
frompcindex
= &froms
[((long)frompcindex
) >> 1];
top
= &tos
[*frompcindex
];
*frompcindex
= ++tos
[0].link
;
if (*frompcindex
>= tolimit
)
top
= &tos
[*frompcindex
];
for (; /* break */; top
= &tos
[top
->link
]) {
if (top
->selfpc
== selfpc
) {
top
->link
= ++tos
[0].link
;
if (top
->link
>= tolimit
)
printf("mcount: tos overflow\n");