/*
 *               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 <iostypes.h>
#include <iop.h>
#include <ios.h>
#include <ioslibc.h>
#include <apputils.h>
#include <elf.h>
#include <sys.h>
#include "minimon0.h"

#define STACK_SIZE    4096              
const u8        _initStack[STACK_SIZE];
const u32       _initStackSize = sizeof(_initStack);

static Command commands[] = {
    {"help",  help,  
     "help              - Print this message", commands},
#if ENABLE_FLASH_COMMANDS
    {"cap", cap, 
     "cap               - Display flash capabilities", 0},
    {"dev", fdSelect, 
     "dev               - Set flash device id", 0},
    {"erase", erase, 
     "erase             - Erase the flash blocks specified", 0},
    {"wrb1", wrb1, 
     "wrb1              - Write boot1 image to block 0 flash", 0},
    {"wrb2", wrb2, 
     "wrb2              - Write boot2 to block 1 of flash", 0},
    {"wrbN", wrbN, 
     "wrbN              - Write block N of flash", 0},
    {"fr", fr, 
     "fr                - Read flash page", 0},
    {"fw", fw, 
     "fw                - Write flash page", 0},
    {"fv", fv, 
     "fv                - Verify flash pages", 0},
    {"br", br, 
     "br                - Read flash block and dump to file", 0},
    {"bwrv", bwrv, 
     "bwrv              - Test to erase/write/read/compare flash block", 0},
#if ENABLE_FLASH_TESTS
    {"testBlk1", testBlk1, 
     "testBlk1          - Special test to erase/write/verify flash block", 0},
#endif
    {"dbg", dbg, 
     "dbg               - Toggle verbose for flash operations", 0},
    {"rderr", rderr, 
     "rderr             - Enable/disable reporting of read error", 0},
#endif /* ENABLE_FLASH_COMMANDS */
#if ENABLE_CACHE_TESTS
    {"cli", cli, 
     "cli               - Test I cache lock code", 0},
    {"cld", cld, 
     "cld               - Test D cache lock code", 0},
    {"cache", cache, 
     "cache             - Various cache operations", 0},
    {"mmu", mmu, 
     "mmu               - Various mmu operations", 0},
#endif /* ENABLE_CACHE_TESTS */
    {"peek", peek, 
     "peek              - Look at a memory location", 0},
    {"poke", poke, 
     "poke              - Set a value to a memory location", 0},
    {"elfload", m_elfload,
     "elfload           - Load an ELF file", 0},
    {"binload", m_binload,
     "binload           - Load a BIN file", 0},
    {"bindump", m_bindump,
     "bindump           - Dump loaded BIN file", 0},
    {"ioprun", m_ioprun,
     "ioprun            - Jump to specified address on IOP", 0},
#if ENABLE_PPCBOOT_COMMANDS
    {"initBootPPC", initBootPPC,
     "initBootPPC       - Initialize hardware. Boot PPC into enhanced mode", 0},
    {"bootPPC", m_bootPPC,
     "bootPPC           - Release PPC out of reset", 0},
    {"refreshNapaLoop", m_refreshNapaLoop,
     "refreshNapaLoop   - Infinite Napa refressh loop", 0},
    {"loadBootPPC", m_loadBootPPC,
     "loadBootPPC       - Load bin file, release PPC out of reset and start infinite Napa refresh loop", 0},
#endif /* ENABLE_PPCBOOT_COMMANDS */
#if ENABLE_MEM_TESTS
    {"mem ", m_memCommands,
     "mem               - Commands to reinitialize and test Napa, GDDR3", 0},
#endif /* ENABLE_MEM_TESTS */
    {0},
};

void
minimon0(void)
{
    char line[LINE_SIZE];
    u32 chipid_major;
    u32 chipid_minor;
    getChipId(&chipid_major, &chipid_minor);

    printf("minimon0 [");
    printf("built: " BUILD_TIME "]\n\n");
    initChip();
    initSWWorkArounds(chipid_major, chipid_minor);
    busWrt32(ACR_INTMASK_TRUSTED, 0);
    while (1) {
        printf("Enter command: ");
        gets(line);
        if (parseCommand(line, commands) < 0) {
            help(line, (void *)commands);
        }
    }
}
