cp: direct all internal guest console messages to sclp
[hvf.git] / cp / nucleus / pgm.c
blobf8adc195149b80c6c0ce0fc26fcc8e5a1eb3ca6e
1 /*
2 * Copyright (c) 2007-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
27 #include <interrupt.h>
28 #include <symtab.h>
29 #include <sclp.h>
30 #include <mm.h>
32 struct stack_frame {
33 u64 back_chain;
34 u64 reserved;
35 u64 gpr[14]; /* GPR 2..GPR 15 */
36 u64 fpr[4]; /* FPR 0, 2, 4, 6 */
40 * NOTE: Be *very* careful not to deref something we're not supposed to, we
41 * don't want to recursively PROG.
43 static void dump_stack(u64 addr)
45 char buf[64];
46 struct stack_frame *cur;
47 u64 start, end;
48 u64 ra;
50 sclp_msg("Stack trace:\n");
52 if (addr > memsize)
53 return;
55 addr &= ~0x7ull;
57 start = addr;
58 end = (addr & ~PAGE_MASK) + PAGE_SIZE - sizeof(struct stack_frame);
60 cur = (struct stack_frame*) addr;
62 while(((u64)cur) >= start && ((u64)cur) < end) {
63 ra = cur->gpr[12];
65 sclp_msg(" %016lx %-s\n", ra,
66 symtab_lookup(ra, buf, sizeof(buf)));
68 if (!cur->back_chain)
69 break;
71 cur = (struct stack_frame*) cur->back_chain;
76 * All is lost! All hands abandon ship!
78 * Try to write out a message to a special buffer to help debugging, and
79 * then stop the CPU.
81 static void abend(void)
83 int i;
85 sclp_msg("ABEND\n");
86 sclp_msg("PROG %04x, ILC %d\n", *PGM_INT_CODE, (*PGM_INT_ILC) >> 1);
87 sclp_msg("\n");
88 for(i=0; i<8; i++)
89 sclp_msg("R%-2d = %016lx R%-2d = %016lx\n",
90 i, PSA_INT_GPR[i], i+8, PSA_INT_GPR[i+8]);
91 sclp_msg("\n");
92 sclp_msg("PSW = %016lx %016lx\n",
93 *((u64*) PGM_INT_OLD_PSW), *(((u64*) PGM_INT_OLD_PSW)+1));
94 sclp_msg("\n");
95 dump_stack(PSA_INT_GPR[15]);
98 * halt the cpu
100 * NOTE: we don't care about not clobbering registers as when this
101 * code executes, the CPU will be stopped.
103 asm volatile(
104 "SR %r1, %r1 # not used, but should be zero\n"
105 "SR %r3, %r3 # CPU Address\n"
106 "SIGP %r1, %r3, 0x05 # Signal, order 0x05\n"
110 * If SIGP failed, loop forever
112 for(;;);
115 void __pgm_int_handler(void)
117 abend();