summaryrefslogtreecommitdiffstats
path: root/src/kernel/exception.C
blob: 47c235fe8f0138a0d78d36ef1cd7f0046dc33f14 (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/kernel/exception.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2010 - 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
#include <assert.h>
#include <kernel/types.h>
#include <kernel/console.H>
#include <kernel/task.H>
#include <kernel/taskmgr.H>
#include <arch/ppc.H>
#include <kernel/vmmmgr.H>

namespace Systemcalls { void TaskEnd(task_t*); }
namespace ExceptionHandles
{
    bool HvEmulation(task_t*);
}

const uint64_t EXCEPTION_SRR1_MASK 	= 0x00000000783F0000;
const uint64_t EXCEPTION_SRR1_HVEMUL	= 0x0000000000080000;

extern "C"
void kernel_execute_prog_ex()
{
    task_t* t = TaskManager::getCurrentTask();
    uint64_t exception = getSRR1() & EXCEPTION_SRR1_MASK;

    bool handled = false;
    switch(exception)
    {
	case EXCEPTION_SRR1_HVEMUL:
	    handled = ExceptionHandles::HvEmulation(t);
	    break;
    }
    if (!handled)
    {
	printk("Program exception, killing task %d\n", t->tid);
	Systemcalls::TaskEnd(t);
    }
}

const uint64_t EXCEPTION_DSISR_MASK	= 0x0000000040000000;
const uint64_t EXCEPTION_DSISR_PTEMISS  = 0x0000000040000000;

extern "C"
void kernel_execute_data_storage()
{
    task_t* t = TaskManager::getCurrentTask();
    uint64_t exception = getDSISR() & EXCEPTION_DSISR_MASK;

    bool handled = false;
    switch(exception)
    {
	case EXCEPTION_DSISR_PTEMISS:
	    handled = VmmManager::pteMiss(t, getDAR());
	    break;
    }
    if (!handled)
    {
	printk("Data Storage exception on %d: %lx, %lx\n",
	       t->tid, getDAR(), getDSISR());
	Systemcalls::TaskEnd(t);
    }
}

extern "C"
void kernel_execute_data_segment()
{
    task_t* t = TaskManager::getCurrentTask();
    printk("Data Segment exception, killing task %d\n", t->tid);
    Systemcalls::TaskEnd(t);
}

const uint64_t EXCEPTION_SRR1_INSTR_MASK    = 0x0000000040000000;
const uint64_t EXCEPTION_SRR1_INSTR_PTEMISS = 0x0000000040000000;

extern "C"
void kernel_execute_inst_storage()
{
    task_t* t = TaskManager::getCurrentTask();
    uint64_t exception = getSRR1() & EXCEPTION_SRR1_INSTR_MASK;

    bool handled = false;
    switch (exception)
    {
        case EXCEPTION_SRR1_INSTR_PTEMISS:
            handled = VmmManager::pteMiss(t, getSRR0());
            break;
    }
    if (!handled)
    {
        printk("Inst Storage exception on %d: %lx, %lx\n",
               t->tid, getSRR0(), getSRR1());
        Systemcalls::TaskEnd(t);
    }
}

extern "C"
void kernel_execute_inst_segment()
{
    task_t* t = TaskManager::getCurrentTask();
    printk("Inst Segment exception, killing task %d\n", t->tid);
    Systemcalls::TaskEnd(t);
}

extern "C"
void kernel_execute_alignment()
{
    task_t* t = TaskManager::getCurrentTask();
    printk("Alignment exception, killing task %d\n", t->tid);
    Systemcalls::TaskEnd(t);
}

extern "C"
void kernel_execute_hype_emu_assist()
{
    task_t* t = TaskManager::getCurrentTask();
    printk("HypeEmu: Illegal instruction in task %d\n"
           "\tHSSR0 = %lx, HEIR = %lx\n", t->tid, getHSRR0(), getHEIR());
    Systemcalls::TaskEnd(t);
}

namespace ExceptionHandles
{
    bool HvEmulation(task_t* t)
    {
	/*printk("NIP = %lx : Inst = %x\n",
	       t->context.nip,
	       (*(uint32_t*)t->context.nip));*/

	uint32_t instruction = *(uint32_t*)t->context.nip;

	    // check for mfsprg3
	if ((instruction & 0xfc1fffff) == 0x7c1342a6)
	{
	    t->context.gprs[(instruction & 0x03E00000) >> 21] =
		    (uint64_t) t;
	    t->context.nip = (void*) (((uint64_t)t->context.nip)+4);
	    return true;
	}

	return false;
    }

}

extern "C"
void kernel_execute_fp_unavail()
{
    task_t* t = TaskManager::getCurrentTask();

    if (t->fp_context)
    {
        printk("Error: FP unavailable while task has FP-context.\n");
        kassert(t->fp_context == NULL);
    }
    else
    {
        // Enable FP by creating a FP context.
        // Context switch code will handle the rest.
        t->fp_context = new context_fp_t;
        memset(t->fp_context, '\0', sizeof(context_fp_t));
    }
}
OpenPOWER on IntegriCloud