/*
 * Top level of example main program to do DV tests running on
 * the verilog model that includes the real ARM7TDMI model
 */

/*
 *              Copyright (C) 2005, BroadOn Communications Corp.
 *
 * These coded instructions, statements, and computer programs contain
 * unpublished  proprietary information of BroadOn Communications Corp.,
 * and  are protected by Federal copyright law. They may not be disclosed
 * to  third  parties or copied or duplicated in any form, in whole or in
 * part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#include <types.h>
#include <sc/sc.h>
#include <sc/dv_boot.h>

char foo[] = "Hello, world\n";
const char bar[] = "Oh, please\n";
char buf[32];

int
strlen(char *s)
{
    int len = 0;

    while (*s++) len++;

    return len; 
}

int 
cpu0main(void)
{
    int i;
    volatile char *cp;

    /* Verify that the data segment is writable */
    foo[0] = 'M';

    DVStartCpu1();

    /* Check that BSS is really cleared */
    for (i = 0; i < sizeof buf; i++)
        if (buf[i] != 0)
            DVExit(-1);
   
    /* Try to modify rodata */
    cp = (char *)bar;
    cp += 4;
    /*
     * Since the data is not in the cache, the data abort doesn't
     * get detected by the cpu.  The write better not work!
     */
    *cp = 'n';
    if (*cp == 'n')
        DVExit(-2);

    /* just spin until cpu1 exits */ 
    while (1) ;

    return 0;
}

int 
cpu1main(void)
{
    int i;
    volatile char *cp;
    volatile u32 *wp;

    /* Verify that the data segment is writable */
    foo[0] = 'J';

    /* Reference contents of data segment */
    i = strlen(foo);

    /* Check that BSS is really cleared */
    for (i = 0; i < sizeof buf; i++)
        if (buf[i] != 0)
            DVExit(-3);
   
    /* Try to modify rodata */
    cp = (char *)bar;
    cp += 5;
    /* touch bar to get it into the cache */
    if (*cp != 'o')
        i++;
    /* this should generate a data abort */
    *cp = 'o';
    if (*cp == 'o')
        DVExit(-4);
    wp = (u32 *) (((u32)bar + 3) & ~3);
    if (*wp != 0x76543210)
        i++;
    *wp = 0x76543210;
    if (*wp == 0x76543210)
        DVExit(-5);

    /* should never get here */ 
    return -6;
}
