summaryrefslogtreecommitdiffstats
path: root/src/lib/ssx_dump.c
blob: 93ce1ead3ed0a404afa436d0ea1ffbb8d2912fd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// $Id: ssx_dump.c,v 1.1.1.1 2013/12/11 20:49:20 bcbrock Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/lib/ssx_dump.c,v $
//-----------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2013
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//-----------------------------------------------------------------------------

/// \file ssx_dump.c
/// \brief Routines for dumping SSX kernel data structures
///
/// \note This is a quick hack to help solve a P8 bringup issue.  This code is
/// PPC405 (OCC) specific, i.e., not "portable" SSX. Ideally this type of dump
/// would be implemented in an external debugging tool as well, however it's
/// simplest to implement here in the execution context.

#include "ssx_dump.h"

#define SSX_DUMP_UNIMPLEMENTED 0x00d86701

static const char* _threadState[] = {
    0,
    "Suspended Runnable",
    "Mapped",
    "Suspended Blocked",
    "Completed",
    "Deleted",
};

static const char* _threadFlags[] = {
    0,
    "Semaphore Pend", 
    "Timer Pend",
    "Timer Pend | Semaphore Pend",
    "Timed Out",
    "Timed Out | Semaphore Pend", 
    "Timed Out | Timer Pend",
    "Timed Out | Timer Pend | Semaphore Pend",
};


static void
_dumpTimer(FILE* stream, SsxTimer* timer)
{
    fprintf(stream, 
            "-- Timer @ %p\n"
            "--     Deque.previous = %p\n"
            "--     Deque.next     = %p\n"
            "--     Timeout        = 0x%016llx\n"
            "--     Period         = 0x%016llx\n"
            "--     Callback       = %p\n"
            "--     Arg            = %p\n"
            "--     Options        = 0x%02x\n",
            timer,
            timer->deque.previous,
            timer->deque.next,
            timer->timeout,
            (unsigned long long)(timer->period),
            timer->callback,
            timer->arg,
            timer->options);
}


static void
_dumpThread(FILE* stream, SsxThread* thread)
{
    SsxThreadContext*        threadCtx;
    SsxThreadContextFullIrq* threadCtxIrq;
    uint32_t srr[4], lr, sp;

    fprintf(stream, 
            "-- Thread mapped at priority %d (%p)\n"
            "--     Thread state        = %s (%d)\n"
            "--     Thread flags        = %s (0x%02x)\n"
            "--     Saved Stack Pointer = %p\n",
            thread->priority, thread,
            _threadState[thread->state], thread->state,
            _threadFlags[thread->flags], thread->flags,
            (void*)thread->saved_stack_pointer);

    if (thread->flags & SSX_THREAD_FLAG_SEMAPHORE_PEND) {

        fprintf(stream, 
                "--     Semaphore           = %p\n",
                (void*)thread->semaphore);
    }
    fprintf(stream, 
            "---------------------------------------------\n");
    
    if (thread->flags & SSX_THREAD_FLAG_TIMER_PEND) {

        _dumpTimer(stream, &(thread->timer));
        fprintf(stream, 
                "---------------------------------------------\n");
    }

    if ((thread == ssx_current()) && !__ssx_kernel_context_any_interrupt()) {

        fprintf(stream,
                "--    This thread is executing ssx_dump()\n");

    } else {

        if (thread == ssx_current()) {

            // This is the interrupted thread, and only has its volatile
            // context saved.  The thread stack pointer is stored in a global
            // kernel variable.

            if (__ssx_kernel_context_critical_interrupt()) {

                SSX_PANIC(SSX_DUMP_UNIMPLEMENTED);
                srr[0] = srr[1] = srr[2] = srr[3] = lr = sp = 0; /* For GCC */

            } else {

                threadCtxIrq = 
                    (SsxThreadContextFullIrq*)__ssx_saved_sp_noncritical;
                srr[0] = threadCtxIrq->srr0;
                srr[1] = threadCtxIrq->srr1;
                srr[2] = threadCtxIrq->srr2;
                srr[3] = threadCtxIrq->srr3;
                lr = threadCtxIrq->lr;
                sp = threadCtxIrq->r1;
            }
        } else {

            // This is a fully swapped-out thread.  The context is saved in
            // at the stored stack pointer.

            threadCtx = (SsxThreadContext*)(thread->saved_stack_pointer); 
            srr[0] = threadCtx->srr0;
            srr[1] = threadCtx->srr1;
            srr[2] = threadCtx->srr2;
            srr[3] = threadCtx->srr3;
            lr = threadCtx->lr;
            sp = ((uint32_t*)threadCtx->r1)[0];
        }

        fprintf(stream,
                "--    SRR0: 0x%08x  SRR1: 0x%08x  "
                "SRR2: 0x%08x  SRR3: 0x%08x\n"
                "--      LR: 0x%08x\n",
                srr[0], srr[1], srr[2], srr[3],
                lr);

        fprintf(stream, 
                "---------------------------------------------\n");

        // Unwind the stack

        while (sp != 0) {

            fprintf(stream, 
                    "--      SP: 0x%08x  *LR*:0x%08x\n",
                    sp, ((uint32_t*)sp)[1]);
            sp = ((uint32_t*)sp)[0];
        }
    }
}




void
ssx_dump(FILE* stream, int options)
{
    int i, sep;
    SsxThread* thread;

    fprintf(stream, 
            "------------------------------------------------------------\n");
    fprintf(stream,
            "-- SSX Kernel Dump @ 0x%016llx\n"
            "--          USPRG0 = 0x%08x\n"
            "-- __ssx_run_queue = 0x%08x\n",
            ssx_timebase_get(), 
            mfspr(SPRN_USPRG0),
            __ssx_run_queue);
    fprintf(stream, 
            "------------------------------------------------------------\n");

    sep = 0;

    for (i = 0; i < SSX_THREADS; i++) {

        ssx_thread_at_priority(i, &thread);
        if (thread) {
            if (sep) {
                fprintf(stream, 
                        "*********************************************\n");
            }
            _dumpThread(stream, thread);
            sep = 1;
        }
    }

    fprintf(stream, 
            "------------------------------------------------------------\n");
}

    
        

            

            

OpenPOWER on IntegriCloud