add some trace apis

This commit is contained in:
Yanyan Jiang 2018-08-10 05:15:06 +00:00
parent 20249fdcf1
commit d41a3656aa
4 changed files with 44 additions and 8 deletions

View File

@ -1,7 +1,29 @@
#ifndef __AMTRACE_H__
#define __AMTRACE_H__
void _trace_on();
void _trace_off();
struct _Trace {
uint8_t cpu;
uint8_t type;
uint16_t length;
char payload[];
} __attribute__((packed));
typedef struct _Trace _Trace;
// ========================= trace components ========================
#define _TRACE_IOE 0x00000001
#define _TRACE_ASYE 0x00000002
#define _TRACE_PTE 0x00000004
#define _TRACE_MPE 0x00000008
// =========================== trace points ==========================
#define _TRACE_CALL 0x00010000
#define _TRACE_RET 0x00020000
#define _TRACE_FUNC (_TRACE_CALL | _TRACE_RET)
#define _TRACE_ALL 0xffffffff
void _trace_on(uint32_t flags);
void _trace_off(uint32_t flags);
#endif

View File

@ -8,7 +8,7 @@
extern volatile uint32_t *lapic;
extern int ncpu;
extern volatile int trace_on;
extern volatile uint32_t trace_flags;
void lapic_eoi();
void lapic_init();
@ -60,4 +60,15 @@ void vec14();
void vecsys();
void irqall();
static inline int traced() {
#ifdef EXT
uint32_t flags = trace_flags;
if ( (flags & _TRACE_##EXT) && // the extension is being traced
1) {
return 1;
}
#endif
return 0;
}
#endif

View File

@ -1,11 +1,12 @@
#include <am-x86.h>
volatile int trace_on = 0;
volatile uint32_t trace_flags = 0;
void _trace_on() {
_atomic_xchg(&trace_on, 1);
void _trace_on(uint32_t flags) {
// TODO: multiprocessor safety
trace_flags |= flags;
}
void _trace_off() {
_atomic_xchg(&trace_on, 0);
void _trace_off(uint32_t flags) {
trace_flags &= ~flags;
}

View File

@ -1,5 +1,6 @@
#include <am.h>
#include <amdev.h>
#include <amtrace.h>
#include <klib.h>
_Context *uctx;
@ -61,6 +62,7 @@ uint8_t code[] = {
uint8_t kstk[4096];
int main() {
_trace_on(_TRACE_ALL);
st = (uintptr_t)_heap.start;
_ioe_init();
_asye_init(handler);