akaros/kern/arch/x86/kdebug.h
<<
>>
Prefs
   1/* Copyright (c) 2011 The Regents of the University of California
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   5 * x86-specific Kernel debugging headers and static inlines */
   6
   7#pragma once
   8
   9#include <ros/common.h>
  10#include <arch/x86.h>
  11
  12/* Returns a PC/EIP in the function that called us, preferably near the call
  13 * site.  Returns 0 when we can't jump back any farther. */
  14static inline uintptr_t get_caller_pc(void)
  15{
  16        unsigned long *ebp = (unsigned long*)read_bp();
  17
  18        if (!ebp)
  19                return 0;
  20        /* this is part of the way back into the call() instruction's bytes
  21         * eagle-eyed readers should be able to explain why this is good enough,
  22         * and retaddr (just *(ebp + 1) is not) */
  23        return *(ebp + 1) - 1;
  24}
  25
  26static inline uintptr_t get_caller_fp(void)
  27{
  28        unsigned long *ebp = (unsigned long*)read_bp();
  29
  30        if (!ebp)
  31                return 0;
  32        return *ebp;
  33}
  34