/******************************************************************************
 *
 *                                  Cpu
 *
 * This module contains the functions which control the CPU driver.
 *
 * History:
 *   +----------+------------+------------------------------------------------+
 *   |   Date   |     by     |     Description                                |
 *   +----------+------------+------------------------------------------------+
 *   |          | Coby       | Written                                        |
 *   +----------+------------+------------------------------------------------+
 * 
 *****************************************************************************/


#include "cc_def.h"
#include "global_f.h"
#include "cpu.h"
#include "cpu_d.h"

/*
 * Define local functions
 */




/*^L*/
/*-----------------------------------------------------------------------------
 *
 *                 Ri_decode__(cmd, response)
 *
 * This function decodes the reset intbase command.
 *
 *---------------------------------------------------------------------------*/

public void ri_decode__(cmd, response)
    str     cmd, response;
{ 

    unsigned	cfg_val;
#   if (NON_DE_AVAILABLE)
	put_reg_val__(&IN__, &cmon_normal_intbase__);
#       if (DE_AVAILABLE)
	    change_exception_mode__(NON_DIRECT_EXCEPTION_MODE);
#       endif
#    else
	put_reg_val__(&IN__, &cmon_de_intbase__);
#    endif

} /* ri_decode__ */

/*^L*/
/*-----------------------------------------------------------------------------
 *
 *                 De_decode__(cmd, response)
 *
 * This function decodes the direct exception command.
 *
 *---------------------------------------------------------------------------*/

public void de_decode__(cmd, response)
    str     cmd, response;
{
#if (NON_DE_AVAILABLE && DE_AVAILABLE)

    int mode;

    /*
     * A direct exception command must be 4 characters long.
     */

    if (strlen(cmd) != 4) {
        ERROR(e_syntax__);
    }

    /*
     * Check the current direct exception mode. 
     */

    mode = exception_mode__();

    /*
     * According to the parameter, set the direct exception mode. If the
     * parameter requests the same mode which already exists, no change is
     * done. The INTBASE register is set accordingly.
     */

    if (cmd[3] == 'E') {
        if (mode != DIRECT_EXCEPTION_MODE) {
            change_exception_mode__(DIRECT_EXCEPTION_MODE);
	    put_reg_val__(&IN__, &cmon_de_intbase__);
        }
    }
    else if (cmd[3] == 'D') {
        if (mode != NON_DIRECT_EXCEPTION_MODE) {
            change_exception_mode__(NON_DIRECT_EXCEPTION_MODE);
	    put_reg_val__(&IN__, &cmon_normal_intbase__);
        }
    }
    else {
        ERROR( e_syntax__);
    }

#endif

} /* de_decode__ */

/*^L*/
/*-----------------------------------------------------------------------------
 *
 *                 Iv_decode__(cmd, response)
 *
 * This function decodes the invalidate cache command.
 *
 *---------------------------------------------------------------------------*/

public void iv_decode__(cmd, response)
    str      cmd, response;
{ 
    boolean  all_entries, err, available;
    s_str    hex_addr;
    int      cmd_len;
    unsigned len;

    /*
     * An invalidate cache command must be at least 4 characters long.
     */

    cmd_len = strlen(cmd);
    if (cmd_len < 4) {
        ERROR( e_syntax__);
    }

    /*
     * Get the entries parameter.
     */

    all_entries = TRUE;
    hex_addr[0]  = '\0';
    if (cmd_len > 4) {
        if (cmd[4] != ' ') {
            ERROR( e_syntax__);
        }
        if (cmd[5] == 'A') {
            if (cmd_len > 6) {
                ERROR( e_syntax__);
            }
        }
#if (CORE_TYPE != SF)
        else if (cmd[5] == 'E') {
            get_first_arg__(&cmd[6], hex_addr, &len, S_SIZE,
	                   /* accept null arg */ FALSE);
            if (cmd_len > len+7) {
                ERROR( e_syntax__);
            }
            all_entries = FALSE;
        }
#endif
        else {
            ERROR( e_syntax__);
            return;
        }
    } /* if (cmd_len > 4) */

    /*
     * Invalidate the entrie(s).
     */

    invalidate_cache__(cmd[3], all_entries, hex_addr,0, &available);
    if (NOT available) {
        ERROR( e_syntax__);
    }

} /* iv_decode__ */

