1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/stdarg.h>
4 #include <linux/string.h>
5 #include <linux/ctype.h>
6 #include <asm/stacktrace.h>
7 #include <asm/boot_data.h>
8 #include <asm/lowcore.h>
14 const char hex_asc[] = "0123456789abcdef";
16 static char *as_hex(char *dst, unsigned long val, int pad)
18 char *p, *end = p = dst + max(pad, (int)__fls(val | 1) / 4 + 1);
20 for (*p-- = 0; p >= dst; val >>= 4)
21 *p-- = hex_asc[val & 0x0f];
25 static char *symstart(char *p)
32 static noinline char *findsym(unsigned long ip, unsigned short *off, unsigned short *len)
34 /* symbol entries are in a form "10000 c4 startup\0" */
35 char *a = _decompressor_syms_start;
36 char *b = _decompressor_syms_end;
43 pivot = symstart(a + (b - a) / 2);
44 start = simple_strtoull(pivot, &endp, 16);
45 size = simple_strtoull(endp + 1, &endp, 16);
50 if (ip > start + size) {
51 a = pivot + strlen(pivot) + 1;
61 static noinline char *strsym(void *ip)
68 p = findsym((unsigned long)ip, &off, &len);
70 strncpy(buf, p, sizeof(buf));
71 /* reserve 15 bytes for offset/len in symbol+0x1234/0x1234 */
72 p = buf + strnlen(buf, sizeof(buf) - 15);
74 p = as_hex(p + 3, off, 0);
76 as_hex(p + 3, len, 0);
78 as_hex(buf, (unsigned long)ip, 16);
83 void decompressor_printk(const char *fmt, ...)
85 char buf[1024] = { 0 };
86 char *end = buf + sizeof(buf) - 1; /* make sure buf is 0 terminated */
92 for (; p < end && *fmt; fmt++) {
97 pad = isdigit(*++fmt) ? simple_strtol(fmt, (char **)&fmt, 10) : 0;
100 p = buf + strlcat(buf, va_arg(args, char *), sizeof(buf));
105 p = buf + strlcat(buf, strsym(va_arg(args, void *)), sizeof(buf));
108 if (*++fmt != 'x' || end - p <= max(sizeof(long) * 2, pad))
110 p = as_hex(p, va_arg(args, unsigned long), pad);
113 if (end - p <= max(sizeof(int) * 2, pad))
115 p = as_hex(p, va_arg(args, unsigned int), pad);
123 sclp_early_printk(buf);
126 void print_stacktrace(unsigned long sp)
128 struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start,
129 (unsigned long)_stack_end };
132 decompressor_printk("Call Trace:\n");
133 while (!(sp & 0x7) && on_stack(&boot_stack, sp, sizeof(struct stack_frame))) {
134 struct stack_frame *sf = (struct stack_frame *)sp;
136 decompressor_printk(first ? "(sp:%016lx [<%016lx>] %pS)\n" :
137 " sp:%016lx [<%016lx>] %pS\n",
138 sp, sf->gprs[8], (void *)sf->gprs[8]);
139 if (sf->back_chain <= sp)
146 void print_pgm_check_info(void)
148 unsigned long *gpregs = (unsigned long *)S390_lowcore.gpregs_save_area;
149 struct psw_bits *psw = &psw_bits(S390_lowcore.psw_save_area);
151 decompressor_printk("Linux version %s\n", kernel_version);
152 if (!is_prot_virt_guest() && early_command_line[0])
153 decompressor_printk("Kernel command line: %s\n", early_command_line);
154 decompressor_printk("Kernel fault: interruption code %04x ilc:%x\n",
155 S390_lowcore.pgm_code, S390_lowcore.pgm_ilc >> 1);
157 decompressor_printk("Kernel random base: %lx\n", __kaslr_offset);
158 decompressor_printk("PSW : %016lx %016lx (%pS)\n",
159 S390_lowcore.psw_save_area.mask,
160 S390_lowcore.psw_save_area.addr,
161 (void *)S390_lowcore.psw_save_area.addr);
163 " R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x P:%x AS:%x CC:%x PM:%x RI:%x EA:%x\n",
164 psw->per, psw->dat, psw->io, psw->ext, psw->key, psw->mcheck,
165 psw->wait, psw->pstate, psw->as, psw->cc, psw->pm, psw->ri,
167 decompressor_printk("GPRS: %016lx %016lx %016lx %016lx\n",
168 gpregs[0], gpregs[1], gpregs[2], gpregs[3]);
169 decompressor_printk(" %016lx %016lx %016lx %016lx\n",
170 gpregs[4], gpregs[5], gpregs[6], gpregs[7]);
171 decompressor_printk(" %016lx %016lx %016lx %016lx\n",
172 gpregs[8], gpregs[9], gpregs[10], gpregs[11]);
173 decompressor_printk(" %016lx %016lx %016lx %016lx\n",
174 gpregs[12], gpregs[13], gpregs[14], gpregs[15]);
175 print_stacktrace(S390_lowcore.gpregs_save_area[15]);
176 decompressor_printk("Last Breaking-Event-Address:\n");
177 decompressor_printk(" [<%016lx>] %pS\n", (unsigned long)S390_lowcore.pgm_last_break,
178 (void *)S390_lowcore.pgm_last_break);