?? boot.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: boot.c
** Last modified Date: 2005-02-24
** Last Version: 1.0
** Descriptions: zlg/boot v1.0
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2005-02-24
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#define IN_BOOT
#include "config.h"
static uint8 Cmdload(char *Parameter, uint8 PLen);
static uint8 CmdSet(char *Parameter, uint8 PLen);
static uint8 CmdRun(char *Parameter, uint8 PLen);
static uint8 CmdSfr(char *Parameter, uint8 PLen);
static uint8 CmdSfrh(char *Parameter, uint8 PLen);
static uint8 CmdSfrb(char *Parameter, uint8 PLen);
#define REG_CPSR 0
#define USR_R13 1
#define USR_R14 2
#define UND_R13 3
#define UND_R14 4
#define SVC_R13 5
#define SVC_R14 6
#define IRQ_R13 7
#define IRQ_R14 8
#define FIQ_R8 9
#define FIQ_R9 10
#define FIQ_R10 11
#define FIQ_R11 12
#define FIQ_R12 13
#define FIQ_R13 14
#define FIQ_R14 15
#define USR_R0 16
#define USR_R1 17
#define USR_R2 18
#define USR_R3 19
#define USR_R4 20
#define USR_R5 21
#define USR_R6 22
#define USR_R7 23
#define USR_R8 24
#define USR_R9 25
#define USR_R10 26
#define USR_R11 27
#define USR_R12 28
#define ABT_R13 29
#define ABT_R14 30
#define PC_REG 31
uint32 Regs[32];
typedef struct
{
char *RegName;
uint8 Index;
}_REG;
const static _REG RegTable[] =
{
{"CPSR", REG_CPSR},
{"R0", USR_R0},
{"R1", USR_R1},
{"R2", USR_R2},
{"R3", USR_R3},
{"R4", USR_R4},
{"R5", USR_R5},
{"R6", USR_R6},
{"R7", USR_R7},
{"R8", USR_R8},
{"R9", USR_R9},
{"R10", USR_R10},
{"R11", USR_R11},
{"R12", USR_R12},
{"R13", USR_R13},
{"R14", USR_R14},
{"R15", PC_REG},
{"SP", USR_R13},
{"LR", USR_R14},
{"PC", PC_REG},
{"R13_UND", UND_R13},
{"R14_UND", UND_R14},
{"SP_UND", UND_R13},
{"LR_UND", UND_R14},
{"R13_SVC", SVC_R13},
{"R14_SVC", SVC_R14},
{"SP_SVC", SVC_R13},
{"LR_SVC", SVC_R14},
{"R13_IRQ", IRQ_R13},
{"R14_IRQ", IRQ_R14},
{"SP_IRQ", IRQ_R13},
{"LR_IRQ", IRQ_R14},
{"R13_ABT", ABT_R13},
{"R14_ABT", ABT_R14},
{"SP_ABT", ABT_R13},
{"LR_ABT", ABT_R14},
{"R8_FIQ", FIQ_R8},
{"R9_FIQ", FIQ_R9},
{"R10_FIQ", FIQ_R10},
{"R11_FIQ", FIQ_R11},
{"R12_FIQ", FIQ_R12},
{"R13_FIQ", FIQ_R13},
{"R14_FIQ", FIQ_R14},
{"SP_FIQ", FIQ_R13},
{"LR_FIQ", FIQ_R14},
{NULL, 0}
};
typedef struct
{
char *CmdName;
uint8 (* Cmd)(char *Parameter, uint8 PLen);
}_CMD;
const static _CMD CmdData[] =
{
{"LOAD", Cmdload},
{"RUN", CmdRun},
{"SET", CmdSet},
{"SFR", CmdSfr},
{"SFRW", CmdSfr},
{"SFRH", CmdSfrh},
{"SFRB", CmdSfrb},
{NULL, NULL}
};
/*********************************************************************************************************
** Function name: Cmdload
** Descriptions: load data in ram
** Input:Parameter: Parameter string
** PLen: Parameter string length
** Output: TRUE: OK
** FALSE: NOT OK
** Created by: chenmingji
** Created Date: 2005-02-24
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static uint8 Cmdload(char *Parameter, uint8 PLen)
{
HANDLE Handle;
uint32 Addr, Length;
char Ch;
if (PLen < 1)
{
return FALSE;
}
PLen--;
Parameter++;
sscanf(Parameter, "0X%X", &Addr);
if (Addr >= BOTTOM_OF_USR)
{
return FALSE;
}
Length = BOTTOM_OF_USR - Addr;
do
{
Ch = *Parameter++;
if (Ch == ' ')
{
break;
}
}while (--PLen != 0);
if (PLen == 0)
{
return FALSE;
}
Handle = FileOpen(Parameter, "r");
if (Handle == Not_Open_FILE)
{
return FALSE;
}
FileRead((void *)Addr, Length, Handle);
FileClose(Handle);
return TRUE;
}
/*********************************************************************************************************
** Function name: CmdSet
** Descriptions: Set register cmd
** Input:Parameter: Parameter string
** PLen: Parameter string length
** Output: TRUE: OK
** FALSE: NOT OK
** Created by: chenmingji
** Created Date: 2005-02-24
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static uint8 CmdSet(char *Parameter, uint8 PLen)
{
const _REG *reg;
char *cp1, *cp2;
char temp;
unsigned int i;
uint32 Data;
if (PLen < 1)
{
return FALSE;
}
Parameter++;
PLen--;
reg = RegTable;
while (reg->RegName != NULL)
{
cp1 = reg->RegName;
cp2 = Parameter;
i = PLen;
do
{
temp = *cp2;
if (temp == ' ' || temp == '=')
{
cp2++;
sscanf(cp2, "0X%X", &Data);
Regs[reg->Index] = Data;
return TRUE;
}
if (temp == 0)
{
break;
}
if (*cp1 == temp)
{
cp1++;
cp2++;
continue;
}
break;
} while (--i != 0);
reg++;
}
return FALSE;
}
/*********************************************************************************************************
** Function name: CmdSfr** Descriptions: Set 32bit register cmd
** Input:Parameter: Parameter string
** PLen: Parameter string length
** Output: TRUE: OK
** FALSE: NOT OK
** Created by: chenmingji
** Created Date: 2005-02-24
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -