1*a47a12beSStefan Roese /* 2*a47a12beSStefan Roese * (C) Copyright 2002 3*a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4*a47a12beSStefan Roese * 5*a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 6*a47a12beSStefan Roese * project. 7*a47a12beSStefan Roese * 8*a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 9*a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 10*a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 11*a47a12beSStefan Roese * the License, or (at your option) any later version. 12*a47a12beSStefan Roese * 13*a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 14*a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a47a12beSStefan Roese * GNU General Public License for more details. 17*a47a12beSStefan Roese * 18*a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 19*a47a12beSStefan Roese * along with this program; if not, write to the Free Software 20*a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*a47a12beSStefan Roese * MA 02111-1307 USA 22*a47a12beSStefan Roese */ 23*a47a12beSStefan Roese 24*a47a12beSStefan Roese #include <common.h> 25*a47a12beSStefan Roese 26*a47a12beSStefan Roese /* 27*a47a12beSStefan Roese * CPU test 28*a47a12beSStefan Roese * Complex calculations 29*a47a12beSStefan Roese * 30*a47a12beSStefan Roese * The calculations in this test are just a combination of simpler 31*a47a12beSStefan Roese * calculations, but probably under different timing conditions, etc. 32*a47a12beSStefan Roese */ 33*a47a12beSStefan Roese 34*a47a12beSStefan Roese #include <post.h> 35*a47a12beSStefan Roese #include "cpu_asm.h" 36*a47a12beSStefan Roese 37*a47a12beSStefan Roese #if CONFIG_POST & CONFIG_SYS_POST_CPU 38*a47a12beSStefan Roese 39*a47a12beSStefan Roese extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n); 40*a47a12beSStefan Roese extern int cpu_post_complex_2_asm (int x, int n); 41*a47a12beSStefan Roese 42*a47a12beSStefan Roese /* 43*a47a12beSStefan Roese * n 44*a47a12beSStefan Roese * SUM (a1 * a2 - a3) / a4 = n * result 45*a47a12beSStefan Roese * i=1 46*a47a12beSStefan Roese */ 47*a47a12beSStefan Roese static int cpu_post_test_complex_1 (void) 48*a47a12beSStefan Roese { 49*a47a12beSStefan Roese int a1 = 666; 50*a47a12beSStefan Roese int a2 = 667; 51*a47a12beSStefan Roese int a3 = 668; 52*a47a12beSStefan Roese int a4 = 66; 53*a47a12beSStefan Roese int n = 100; 54*a47a12beSStefan Roese int result = 6720; /* (a1 * a2 - a3) / a4 */ 55*a47a12beSStefan Roese 56*a47a12beSStefan Roese if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result) 57*a47a12beSStefan Roese { 58*a47a12beSStefan Roese return -1; 59*a47a12beSStefan Roese } 60*a47a12beSStefan Roese 61*a47a12beSStefan Roese return 0; 62*a47a12beSStefan Roese } 63*a47a12beSStefan Roese 64*a47a12beSStefan Roese /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1) 65*a47a12beSStefan Roese */ 66*a47a12beSStefan Roese static int cpu_post_test_complex_2 (void) 67*a47a12beSStefan Roese { 68*a47a12beSStefan Roese int ret = -1; 69*a47a12beSStefan Roese int x; 70*a47a12beSStefan Roese int n; 71*a47a12beSStefan Roese int k; 72*a47a12beSStefan Roese int left; 73*a47a12beSStefan Roese int right; 74*a47a12beSStefan Roese 75*a47a12beSStefan Roese for (x = -8; x <= 8; x ++) 76*a47a12beSStefan Roese { 77*a47a12beSStefan Roese n = 9; 78*a47a12beSStefan Roese 79*a47a12beSStefan Roese left = cpu_post_complex_2_asm(x, n); 80*a47a12beSStefan Roese left *= 1 - x; 81*a47a12beSStefan Roese 82*a47a12beSStefan Roese right = 1; 83*a47a12beSStefan Roese for (k = 0; k <= n; k ++) 84*a47a12beSStefan Roese { 85*a47a12beSStefan Roese right *= x; 86*a47a12beSStefan Roese } 87*a47a12beSStefan Roese right = 1 - right; 88*a47a12beSStefan Roese 89*a47a12beSStefan Roese if (left != right) 90*a47a12beSStefan Roese { 91*a47a12beSStefan Roese goto Done; 92*a47a12beSStefan Roese } 93*a47a12beSStefan Roese } 94*a47a12beSStefan Roese 95*a47a12beSStefan Roese ret = 0; 96*a47a12beSStefan Roese Done: 97*a47a12beSStefan Roese 98*a47a12beSStefan Roese return ret; 99*a47a12beSStefan Roese } 100*a47a12beSStefan Roese 101*a47a12beSStefan Roese int cpu_post_test_complex (void) 102*a47a12beSStefan Roese { 103*a47a12beSStefan Roese int ret = 0; 104*a47a12beSStefan Roese int flag = disable_interrupts(); 105*a47a12beSStefan Roese 106*a47a12beSStefan Roese if (ret == 0) 107*a47a12beSStefan Roese { 108*a47a12beSStefan Roese ret = cpu_post_test_complex_1(); 109*a47a12beSStefan Roese } 110*a47a12beSStefan Roese 111*a47a12beSStefan Roese if (ret == 0) 112*a47a12beSStefan Roese { 113*a47a12beSStefan Roese ret = cpu_post_test_complex_2(); 114*a47a12beSStefan Roese } 115*a47a12beSStefan Roese 116*a47a12beSStefan Roese if (ret != 0) 117*a47a12beSStefan Roese { 118*a47a12beSStefan Roese post_log ("Error at complex test !\n"); 119*a47a12beSStefan Roese } 120*a47a12beSStefan Roese 121*a47a12beSStefan Roese if (flag) 122*a47a12beSStefan Roese enable_interrupts(); 123*a47a12beSStefan Roese 124*a47a12beSStefan Roese return ret; 125*a47a12beSStefan Roese } 126*a47a12beSStefan Roese 127*a47a12beSStefan Roese #endif 128