blob: a66b6a1bc816669c9c0684535cefa8fc2e53e82c [file] [log] [blame]
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -07001/*
2This software and ancillary information (herein called SOFTWARE )
3called LinuxBIOS is made available under the terms described
4here. The SOFTWARE has been approved for release with associated
5LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has
6been authored by an employee or employees of the University of
7California, operator of the Los Alamos National Laboratory under
8Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The
9U.S. Government has rights to use, reproduce, and distribute this
10SOFTWARE. The public may copy, distribute, prepare derivative works
11and publicly display this SOFTWARE without charge, provided that this
12Notice and any statement of authorship are reproduced on all copies.
13Neither the Government nor the University makes any warranty, express
14or implied, or assumes any liability or responsibility for the use of
15this SOFTWARE. If SOFTWARE is modified to produce derivative works,
16such modified SOFTWARE should be clearly marked, so as not to confuse
17it with the version available from LANL.
18 */
19/* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
20 * rminnich@lanl.gov
Lee Leahy73402172017-03-10 15:23:24 -080021 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>,
22 * Raptor Engineering
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070023 */
24
Julius Wernera43db192014-12-15 18:19:03 -080025#include <assert.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070026#include <lib.h>
27#include <console/console.h>
Julius Wernera43db192014-12-15 18:19:03 -080028#include <symbols.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070029
30int checkstack(void *top_of_stack, int core)
31{
Julius Wernera43db192014-12-15 18:19:03 -080032 /* Not all archs use CONFIG_STACK_SIZE, those who don't set it to 0. */
33 size_t stack_size = CONFIG_STACK_SIZE ? CONFIG_STACK_SIZE : _stack_size;
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070034 int i;
Julius Wernera43db192014-12-15 18:19:03 -080035 u32 *stack = (u32 *) (top_of_stack - stack_size);
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070036
Lee Leahy35af5c42017-03-09 17:35:28 -080037 if (stack[0] != 0xDEADBEEF) {
Lee Leahy73402172017-03-10 15:23:24 -080038 printk(BIOS_ERR,
39 "Stack overrun on CPU%d (address %p overwritten). "
Julius Wernera43db192014-12-15 18:19:03 -080040 "Increase stack from current %zu bytes\n",
Timothy Pearson478575c2015-09-05 19:31:03 -050041 core, stack, stack_size);
Julius Wernera43db192014-12-15 18:19:03 -080042 BUG();
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070043 return -1;
44 }
45
Lee Leahy35af5c42017-03-09 17:35:28 -080046 for (i = 1; i < stack_size/sizeof(stack[0]); i++) {
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070047 if (stack[i] == 0xDEADBEEF)
48 continue;
Stefan Reinauer75dbc382012-10-15 15:19:43 -070049 printk(BIOS_SPEW, "CPU%d: stack: %p - %p, ",
Julius Wernera43db192014-12-15 18:19:03 -080050 core, stack, &stack[stack_size/sizeof(stack[0])]);
Stefan Reinauer75dbc382012-10-15 15:19:43 -070051 printk(BIOS_SPEW, "lowest used address %p, ", &stack[i]);
52 printk(BIOS_SPEW, "stack used: %ld bytes\n",
Julius Wernera43db192014-12-15 18:19:03 -080053 (unsigned long)&stack[stack_size / sizeof(stack[0])]
54 - (unsigned long)&stack[i]);
Stefan Reinauer75dbc382012-10-15 15:19:43 -070055 return 0;
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070056 }
57
58 return 0;
59
60}