uboot/post/lib_powerpc/cmp.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * (C) Copyright 2002
   4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   5 */
   6
   7#include <common.h>
   8
   9/*
  10 * CPU test
  11 * Integer compare instructions:        cmpw, cmplw
  12 *
  13 * To verify these instructions the test runs them with
  14 * different combinations of operands, reads the condition
  15 * register value and compares it with the expected one.
  16 * The test contains a pre-built table
  17 * containing the description of each test case: the instruction,
  18 * the values of the operands, the condition field to save
  19 * the result in and the expected result.
  20 */
  21
  22#include <post.h>
  23#include "cpu_asm.h"
  24
  25#if CONFIG_POST & CONFIG_SYS_POST_CPU
  26
  27extern void cpu_post_exec_12 (ulong *code, ulong *res, ulong op1, ulong op2);
  28
  29static struct cpu_post_cmp_s
  30{
  31    ulong cmd;
  32    ulong op1;
  33    ulong op2;
  34    ulong cr;
  35    ulong res;
  36} cpu_post_cmp_table[] =
  37{
  38    {
  39        OP_CMPW,
  40        123,
  41        123,
  42        2,
  43        0x02
  44    },
  45    {
  46        OP_CMPW,
  47        123,
  48        133,
  49        3,
  50        0x08
  51    },
  52    {
  53        OP_CMPW,
  54        123,
  55        -133,
  56        4,
  57        0x04
  58    },
  59    {
  60        OP_CMPLW,
  61        123,
  62        123,
  63        2,
  64        0x02
  65    },
  66    {
  67        OP_CMPLW,
  68        123,
  69        -133,
  70        3,
  71        0x08
  72    },
  73    {
  74        OP_CMPLW,
  75        123,
  76        113,
  77        4,
  78        0x04
  79    },
  80};
  81static unsigned int cpu_post_cmp_size = ARRAY_SIZE(cpu_post_cmp_table);
  82
  83int cpu_post_test_cmp (void)
  84{
  85    int ret = 0;
  86    unsigned int i;
  87    int flag = disable_interrupts();
  88
  89    for (i = 0; i < cpu_post_cmp_size && ret == 0; i++)
  90    {
  91        struct cpu_post_cmp_s *test = cpu_post_cmp_table + i;
  92        unsigned long code[] =
  93        {
  94            ASM_2C(test->cmd, test->cr, 3, 4),
  95            ASM_MFCR(3),
  96            ASM_BLR
  97        };
  98        ulong res;
  99
 100        cpu_post_exec_12 (code, & res, test->op1, test->op2);
 101
 102        ret = ((res >> (28 - 4 * test->cr)) & 0xe) == test->res ? 0 : -1;
 103
 104        if (ret != 0)
 105        {
 106            post_log ("Error at cmp test %d !\n", i);
 107        }
 108    }
 109
 110    if (flag)
 111        enable_interrupts();
 112
 113    return ret;
 114}
 115
 116#endif
 117