Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 1 | /* |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 2 | This software and ancillary information (herein called SOFTWARE) |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 3 | called LinuxBIOS is made available under the terms described |
| 4 | here. The SOFTWARE has been approved for release with associated |
| 5 | LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has |
| 6 | been authored by an employee or employees of the University of |
| 7 | California, operator of the Los Alamos National Laboratory under |
| 8 | Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The |
| 9 | U.S. Government has rights to use, reproduce, and distribute this |
| 10 | SOFTWARE. The public may copy, distribute, prepare derivative works |
| 11 | and publicly display this SOFTWARE without charge, provided that this |
| 12 | Notice and any statement of authorship are reproduced on all copies. |
| 13 | Neither the Government nor the University makes any warranty, express |
| 14 | or implied, or assumes any liability or responsibility for the use of |
| 15 | this SOFTWARE. If SOFTWARE is modified to produce derivative works, |
| 16 | such modified SOFTWARE should be clearly marked, so as not to confuse |
| 17 | it with the version available from LANL. |
| 18 | */ |
| 19 | /* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL |
| 20 | * rminnich@lanl.gov |
Lee Leahy | 7340217 | 2017-03-10 15:23:24 -0800 | [diff] [blame] | 21 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, |
| 22 | * Raptor Engineering |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 25 | #include <assert.h> |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 26 | #include <lib.h> |
| 27 | #include <console/console.h> |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 28 | #include <symbols.h> |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 29 | |
| 30 | int checkstack(void *top_of_stack, int core) |
| 31 | { |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 32 | /* Not all archs use CONFIG_STACK_SIZE, those who don't set it to 0. */ |
Julius Werner | 7e0dea6 | 2019-02-20 18:39:22 -0800 | [diff] [blame] | 33 | size_t stack_size = CONFIG_STACK_SIZE ? |
| 34 | CONFIG_STACK_SIZE : REGION_SIZE(stack); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 35 | int i; |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 36 | u32 *stack = (u32 *) (top_of_stack - stack_size); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 37 | |
Lee Leahy | 35af5c4 | 2017-03-09 17:35:28 -0800 | [diff] [blame] | 38 | if (stack[0] != 0xDEADBEEF) { |
Lee Leahy | 7340217 | 2017-03-10 15:23:24 -0800 | [diff] [blame] | 39 | printk(BIOS_ERR, |
| 40 | "Stack overrun on CPU%d (address %p overwritten). " |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 41 | "Increase stack from current %zu bytes\n", |
Timothy Pearson | 478575c | 2015-09-05 19:31:03 -0500 | [diff] [blame] | 42 | core, stack, stack_size); |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 43 | BUG(); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 44 | return -1; |
| 45 | } |
| 46 | |
Lee Leahy | 35af5c4 | 2017-03-09 17:35:28 -0800 | [diff] [blame] | 47 | for (i = 1; i < stack_size/sizeof(stack[0]); i++) { |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 48 | if (stack[i] == 0xDEADBEEF) |
| 49 | continue; |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 50 | printk(BIOS_SPEW, "CPU%d: stack: %p - %p, ", |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 51 | core, stack, &stack[stack_size/sizeof(stack[0])]); |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 52 | printk(BIOS_SPEW, "lowest used address %p, ", &stack[i]); |
| 53 | printk(BIOS_SPEW, "stack used: %ld bytes\n", |
Julius Werner | a43db19 | 2014-12-15 18:19:03 -0800 | [diff] [blame] | 54 | (unsigned long)&stack[stack_size / sizeof(stack[0])] |
| 55 | - (unsigned long)&stack[i]); |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 56 | return 0; |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | return 0; |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 60 | } |