mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-28 16:14:20 +08:00
add init Jz47xx porting.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@792 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* File : cache.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "mipscfg.h"
|
||||||
|
#include "cache.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern void cache_init(rt_ubase_t cache_size, rt_ubase_t cache_line_size);
|
||||||
|
void r4k_cache_init(void)
|
||||||
|
{
|
||||||
|
cache_init(dcache_size, cpu_dcache_line_size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_cache_flush_all(void)
|
||||||
|
{
|
||||||
|
blast_dcache16();
|
||||||
|
blast_icache16();
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_icache_flush_all(void)
|
||||||
|
{
|
||||||
|
blast_icache16();
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_icache_flush_range(rt_ubase_t addr, rt_ubase_t size)
|
||||||
|
{
|
||||||
|
rt_ubase_t end, a;
|
||||||
|
|
||||||
|
if (size > icache_size)
|
||||||
|
{
|
||||||
|
blast_icache16();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_ubase_t ic_lsize = cpu_icache_line_size();
|
||||||
|
|
||||||
|
a = addr & ~(ic_lsize - 1);
|
||||||
|
end = ((addr + size) - 1) & ~(ic_lsize - 1);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
flush_icache_line(a);
|
||||||
|
if (a == end)
|
||||||
|
break;
|
||||||
|
a += ic_lsize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_icache_lock_range(rt_ubase_t addr, rt_ubase_t size)
|
||||||
|
{
|
||||||
|
rt_ubase_t end, a;
|
||||||
|
rt_ubase_t ic_lsize = cpu_icache_line_size();
|
||||||
|
|
||||||
|
a = addr & ~(ic_lsize - 1);
|
||||||
|
end = ((addr + size) - 1) & ~(ic_lsize - 1);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
lock_icache_line(a);
|
||||||
|
if (a == end)
|
||||||
|
break;
|
||||||
|
a += ic_lsize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_dcache_inv(rt_ubase_t addr, rt_ubase_t size)
|
||||||
|
{
|
||||||
|
rt_ubase_t end, a;
|
||||||
|
rt_ubase_t dc_lsize = cpu_dcache_line_size();
|
||||||
|
|
||||||
|
a = addr & ~(dc_lsize - 1);
|
||||||
|
end = ((addr + size) - 1) & ~(dc_lsize - 1);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
invalidate_dcache_line(a);
|
||||||
|
if (a == end)
|
||||||
|
break;
|
||||||
|
a += dc_lsize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void r4k_dcache_wback_inv(rt_ubase_t addr, rt_ubase_t size)
|
||||||
|
{
|
||||||
|
rt_ubase_t end, a;
|
||||||
|
|
||||||
|
if (size >= dcache_size)
|
||||||
|
{
|
||||||
|
blast_dcache16();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_ubase_t dc_lsize = cpu_dcache_line_size();
|
||||||
|
|
||||||
|
a = addr & ~(dc_lsize - 1);
|
||||||
|
end = ((addr + size) - 1) & ~(dc_lsize - 1);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
flush_dcache_line(a);
|
||||||
|
if (a == end)
|
||||||
|
break;
|
||||||
|
a += dc_lsize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
* File : cpu.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#ifndef __EXCEPTION_H__
|
||||||
|
#define __EXCEPTION_H__
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* important register numbers
|
||||||
|
*/
|
||||||
|
#define REG_EPC 37
|
||||||
|
#define REG_FP 72
|
||||||
|
#define REG_SP 29
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stack layout for the GDB exception handler
|
||||||
|
* Derived from the stack layout described in asm-mips/stackframe.h
|
||||||
|
*
|
||||||
|
* The first PTRSIZE*6 bytes are argument save space for C subroutines.
|
||||||
|
*/
|
||||||
|
#define NUMREGS 90
|
||||||
|
|
||||||
|
#define GDB_FR_REG0 (PTRSIZE*6) /* 0 */
|
||||||
|
#define GDB_FR_REG1 ((GDB_FR_REG0) + LONGSIZE) /* 1 */
|
||||||
|
#define GDB_FR_REG2 ((GDB_FR_REG1) + LONGSIZE) /* 2 */
|
||||||
|
#define GDB_FR_REG3 ((GDB_FR_REG2) + LONGSIZE) /* 3 */
|
||||||
|
#define GDB_FR_REG4 ((GDB_FR_REG3) + LONGSIZE) /* 4 */
|
||||||
|
#define GDB_FR_REG5 ((GDB_FR_REG4) + LONGSIZE) /* 5 */
|
||||||
|
#define GDB_FR_REG6 ((GDB_FR_REG5) + LONGSIZE) /* 6 */
|
||||||
|
#define GDB_FR_REG7 ((GDB_FR_REG6) + LONGSIZE) /* 7 */
|
||||||
|
#define GDB_FR_REG8 ((GDB_FR_REG7) + LONGSIZE) /* 8 */
|
||||||
|
#define GDB_FR_REG9 ((GDB_FR_REG8) + LONGSIZE) /* 9 */
|
||||||
|
#define GDB_FR_REG10 ((GDB_FR_REG9) + LONGSIZE) /* 10 */
|
||||||
|
#define GDB_FR_REG11 ((GDB_FR_REG10) + LONGSIZE) /* 11 */
|
||||||
|
#define GDB_FR_REG12 ((GDB_FR_REG11) + LONGSIZE) /* 12 */
|
||||||
|
#define GDB_FR_REG13 ((GDB_FR_REG12) + LONGSIZE) /* 13 */
|
||||||
|
#define GDB_FR_REG14 ((GDB_FR_REG13) + LONGSIZE) /* 14 */
|
||||||
|
#define GDB_FR_REG15 ((GDB_FR_REG14) + LONGSIZE) /* 15 */
|
||||||
|
#define GDB_FR_REG16 ((GDB_FR_REG15) + LONGSIZE) /* 16 */
|
||||||
|
#define GDB_FR_REG17 ((GDB_FR_REG16) + LONGSIZE) /* 17 */
|
||||||
|
#define GDB_FR_REG18 ((GDB_FR_REG17) + LONGSIZE) /* 18 */
|
||||||
|
#define GDB_FR_REG19 ((GDB_FR_REG18) + LONGSIZE) /* 19 */
|
||||||
|
#define GDB_FR_REG20 ((GDB_FR_REG19) + LONGSIZE) /* 20 */
|
||||||
|
#define GDB_FR_REG21 ((GDB_FR_REG20) + LONGSIZE) /* 21 */
|
||||||
|
#define GDB_FR_REG22 ((GDB_FR_REG21) + LONGSIZE) /* 22 */
|
||||||
|
#define GDB_FR_REG23 ((GDB_FR_REG22) + LONGSIZE) /* 23 */
|
||||||
|
#define GDB_FR_REG24 ((GDB_FR_REG23) + LONGSIZE) /* 24 */
|
||||||
|
#define GDB_FR_REG25 ((GDB_FR_REG24) + LONGSIZE) /* 25 */
|
||||||
|
#define GDB_FR_REG26 ((GDB_FR_REG25) + LONGSIZE) /* 26 */
|
||||||
|
#define GDB_FR_REG27 ((GDB_FR_REG26) + LONGSIZE) /* 27 */
|
||||||
|
#define GDB_FR_REG28 ((GDB_FR_REG27) + LONGSIZE) /* 28 */
|
||||||
|
#define GDB_FR_REG29 ((GDB_FR_REG28) + LONGSIZE) /* 29 */
|
||||||
|
#define GDB_FR_REG30 ((GDB_FR_REG29) + LONGSIZE) /* 30 */
|
||||||
|
#define GDB_FR_REG31 ((GDB_FR_REG30) + LONGSIZE) /* 31 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Saved special registers
|
||||||
|
*/
|
||||||
|
#define GDB_FR_STATUS ((GDB_FR_REG31) + LONGSIZE) /* 32 */
|
||||||
|
#define GDB_FR_LO ((GDB_FR_STATUS) + LONGSIZE) /* 33 */
|
||||||
|
#define GDB_FR_HI ((GDB_FR_LO) + LONGSIZE) /* 34 */
|
||||||
|
#define GDB_FR_BADVADDR ((GDB_FR_HI) + LONGSIZE) /* 35 */
|
||||||
|
#define GDB_FR_CAUSE ((GDB_FR_BADVADDR) + LONGSIZE) /* 36 */
|
||||||
|
#define GDB_FR_EPC ((GDB_FR_CAUSE) + LONGSIZE) /* 37 */
|
||||||
|
|
||||||
|
///*
|
||||||
|
// * Saved floating point registers
|
||||||
|
// */
|
||||||
|
//#define GDB_FR_FPR0 ((GDB_FR_EPC) + LONGSIZE) /* 38 */
|
||||||
|
//#define GDB_FR_FPR1 ((GDB_FR_FPR0) + LONGSIZE) /* 39 */
|
||||||
|
//#define GDB_FR_FPR2 ((GDB_FR_FPR1) + LONGSIZE) /* 40 */
|
||||||
|
//#define GDB_FR_FPR3 ((GDB_FR_FPR2) + LONGSIZE) /* 41 */
|
||||||
|
//#define GDB_FR_FPR4 ((GDB_FR_FPR3) + LONGSIZE) /* 42 */
|
||||||
|
//#define GDB_FR_FPR5 ((GDB_FR_FPR4) + LONGSIZE) /* 43 */
|
||||||
|
//#define GDB_FR_FPR6 ((GDB_FR_FPR5) + LONGSIZE) /* 44 */
|
||||||
|
//#define GDB_FR_FPR7 ((GDB_FR_FPR6) + LONGSIZE) /* 45 */
|
||||||
|
//#define GDB_FR_FPR8 ((GDB_FR_FPR7) + LONGSIZE) /* 46 */
|
||||||
|
//#define GDB_FR_FPR9 ((GDB_FR_FPR8) + LONGSIZE) /* 47 */
|
||||||
|
//#define GDB_FR_FPR10 ((GDB_FR_FPR9) + LONGSIZE) /* 48 */
|
||||||
|
//#define GDB_FR_FPR11 ((GDB_FR_FPR10) + LONGSIZE) /* 49 */
|
||||||
|
//#define GDB_FR_FPR12 ((GDB_FR_FPR11) + LONGSIZE) /* 50 */
|
||||||
|
//#define GDB_FR_FPR13 ((GDB_FR_FPR12) + LONGSIZE) /* 51 */
|
||||||
|
//#define GDB_FR_FPR14 ((GDB_FR_FPR13) + LONGSIZE) /* 52 */
|
||||||
|
//#define GDB_FR_FPR15 ((GDB_FR_FPR14) + LONGSIZE) /* 53 */
|
||||||
|
//#define GDB_FR_FPR16 ((GDB_FR_FPR15) + LONGSIZE) /* 54 */
|
||||||
|
//#define GDB_FR_FPR17 ((GDB_FR_FPR16) + LONGSIZE) /* 55 */
|
||||||
|
//#define GDB_FR_FPR18 ((GDB_FR_FPR17) + LONGSIZE) /* 56 */
|
||||||
|
//#define GDB_FR_FPR19 ((GDB_FR_FPR18) + LONGSIZE) /* 57 */
|
||||||
|
//#define GDB_FR_FPR20 ((GDB_FR_FPR19) + LONGSIZE) /* 58 */
|
||||||
|
//#define GDB_FR_FPR21 ((GDB_FR_FPR20) + LONGSIZE) /* 59 */
|
||||||
|
//#define GDB_FR_FPR22 ((GDB_FR_FPR21) + LONGSIZE) /* 60 */
|
||||||
|
//#define GDB_FR_FPR23 ((GDB_FR_FPR22) + LONGSIZE) /* 61 */
|
||||||
|
//#define GDB_FR_FPR24 ((GDB_FR_FPR23) + LONGSIZE) /* 62 */
|
||||||
|
//#define GDB_FR_FPR25 ((GDB_FR_FPR24) + LONGSIZE) /* 63 */
|
||||||
|
//#define GDB_FR_FPR26 ((GDB_FR_FPR25) + LONGSIZE) /* 64 */
|
||||||
|
//#define GDB_FR_FPR27 ((GDB_FR_FPR26) + LONGSIZE) /* 65 */
|
||||||
|
//#define GDB_FR_FPR28 ((GDB_FR_FPR27) + LONGSIZE) /* 66 */
|
||||||
|
//#define GDB_FR_FPR29 ((GDB_FR_FPR28) + LONGSIZE) /* 67 */
|
||||||
|
//#define GDB_FR_FPR30 ((GDB_FR_FPR29) + LONGSIZE) /* 68 */
|
||||||
|
//#define GDB_FR_FPR31 ((GDB_FR_FPR30) + LONGSIZE) /* 69 */
|
||||||
|
//
|
||||||
|
//#define GDB_FR_FSR ((GDB_FR_FPR31) + LONGSIZE) /* 70 */
|
||||||
|
//#define GDB_FR_FIR ((GDB_FR_FSR) + LONGSIZE) /* 71 */
|
||||||
|
//#define GDB_FR_FRP ((GDB_FR_FIR) + LONGSIZE) /* 72 */
|
||||||
|
//
|
||||||
|
//#define GDB_FR_DUMMY ((GDB_FR_FRP) + LONGSIZE) /* 73, unused ??? */
|
||||||
|
//
|
||||||
|
///*
|
||||||
|
// * Again, CP0 registers
|
||||||
|
// */
|
||||||
|
//#define GDB_FR_CP0_INDEX ((GDB_FR_DUMMY) + LONGSIZE) /* 74 */
|
||||||
|
#define GDB_FR_FRP ((GDB_FR_EPC) + LONGSIZE) /* 72 */
|
||||||
|
#define GDB_FR_CP0_INDEX ((GDB_FR_FRP) + LONGSIZE) /* 74 */
|
||||||
|
|
||||||
|
#define GDB_FR_CP0_RANDOM ((GDB_FR_CP0_INDEX) + LONGSIZE) /* 75 */
|
||||||
|
#define GDB_FR_CP0_ENTRYLO0 ((GDB_FR_CP0_RANDOM) + LONGSIZE)/* 76 */
|
||||||
|
#define GDB_FR_CP0_ENTRYLO1 ((GDB_FR_CP0_ENTRYLO0) + LONGSIZE)/* 77 */
|
||||||
|
#define GDB_FR_CP0_CONTEXT ((GDB_FR_CP0_ENTRYLO1) + LONGSIZE)/* 78 */
|
||||||
|
#define GDB_FR_CP0_PAGEMASK ((GDB_FR_CP0_CONTEXT) + LONGSIZE)/* 79 */
|
||||||
|
#define GDB_FR_CP0_WIRED ((GDB_FR_CP0_PAGEMASK) + LONGSIZE)/* 80 */
|
||||||
|
#define GDB_FR_CP0_REG7 ((GDB_FR_CP0_WIRED) + LONGSIZE) /* 81 */
|
||||||
|
#define GDB_FR_CP0_REG8 ((GDB_FR_CP0_REG7) + LONGSIZE) /* 82 */
|
||||||
|
#define GDB_FR_CP0_REG9 ((GDB_FR_CP0_REG8) + LONGSIZE) /* 83 */
|
||||||
|
#define GDB_FR_CP0_ENTRYHI ((GDB_FR_CP0_REG9) + LONGSIZE) /* 84 */
|
||||||
|
#define GDB_FR_CP0_REG11 ((GDB_FR_CP0_ENTRYHI) + LONGSIZE)/* 85 */
|
||||||
|
#define GDB_FR_CP0_REG12 ((GDB_FR_CP0_REG11) + LONGSIZE) /* 86 */
|
||||||
|
#define GDB_FR_CP0_REG13 ((GDB_FR_CP0_REG12) + LONGSIZE) /* 87 */
|
||||||
|
#define GDB_FR_CP0_REG14 ((GDB_FR_CP0_REG13) + LONGSIZE) /* 88 */
|
||||||
|
#define GDB_FR_CP0_PRID ((GDB_FR_CP0_REG14) + LONGSIZE) /* 89 */
|
||||||
|
|
||||||
|
#define GDB_FR_SIZE ((((GDB_FR_CP0_PRID) + LONGSIZE) + (PTRSIZE-1)) & ~(PTRSIZE-1))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the same as above, but for the high-level
|
||||||
|
* part of the INT stub.
|
||||||
|
*/
|
||||||
|
typedef struct pt_regs_s
|
||||||
|
{
|
||||||
|
/* Saved main processor registers. */
|
||||||
|
rt_base_t regs[32];
|
||||||
|
/* Saved special registers. */
|
||||||
|
rt_base_t cp0_status;
|
||||||
|
rt_base_t hi;
|
||||||
|
rt_base_t lo;
|
||||||
|
rt_base_t cp0_badvaddr;
|
||||||
|
rt_base_t cp0_cause;
|
||||||
|
rt_base_t cp0_epc;
|
||||||
|
} pt_regs_t;
|
||||||
|
|
||||||
|
typedef void (* exception_func_t)(pt_regs_t *regs);
|
||||||
|
|
||||||
|
extern exception_func_t sys_exception_handlers[33];
|
||||||
|
exception_func_t rt_set_except_vector(int n, exception_func_t func);
|
||||||
|
void install_default_execpt_handle(void);
|
||||||
|
|
||||||
|
#endif /* end of __EXCEPTION_H__ */
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* File : mips.inc
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 sangwei first version
|
||||||
|
*/
|
||||||
|
#ifndef __MIPS_INC__
|
||||||
|
#define __MIPS_INC__
|
||||||
|
|
||||||
|
#define zero $0
|
||||||
|
#define at $1
|
||||||
|
#define v0 $2
|
||||||
|
#define v1 $3
|
||||||
|
#define a0 $4
|
||||||
|
#define a1 $5
|
||||||
|
#define a2 $6
|
||||||
|
#define a3 $7
|
||||||
|
#define t0 $8
|
||||||
|
#define t1 $9
|
||||||
|
#define t2 $10
|
||||||
|
#define t3 $11
|
||||||
|
#define t4 $12
|
||||||
|
#define t5 $13
|
||||||
|
#define t6 $14
|
||||||
|
#define t7 $15
|
||||||
|
#define s0 $16
|
||||||
|
#define s1 $17
|
||||||
|
#define s2 $18
|
||||||
|
#define s3 $19
|
||||||
|
#define s4 $20
|
||||||
|
#define s5 $21
|
||||||
|
#define s6 $22
|
||||||
|
#define s7 $23
|
||||||
|
#define t8 $24
|
||||||
|
#define t9 $25
|
||||||
|
#define k0 $26
|
||||||
|
#define k1 $27
|
||||||
|
#define gp $28
|
||||||
|
#define sp $29
|
||||||
|
#define fp $30
|
||||||
|
#define ra $31
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* end of __MIPS_INC__ */
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* File : mipscfg.h
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-27 swkyer first version
|
||||||
|
*/
|
||||||
|
#ifndef __MIPSCFG_H__
|
||||||
|
#define __MIPSCFG_H__
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mips32_core_cfg
|
||||||
|
{
|
||||||
|
rt_uint16_t icache_line_size;
|
||||||
|
rt_uint16_t icache_lines_per_way;
|
||||||
|
rt_uint16_t icache_ways;
|
||||||
|
rt_uint16_t dcache_line_size;
|
||||||
|
rt_uint16_t dcache_lines_per_way;
|
||||||
|
rt_uint16_t dcache_ways;
|
||||||
|
|
||||||
|
rt_uint16_t max_tlb_entries; /* number of tlb entry */
|
||||||
|
} mips32_core_cfg_t;
|
||||||
|
|
||||||
|
extern mips32_core_cfg_t g_mips_core;
|
||||||
|
|
||||||
|
#endif /* end of __MIPSCFG_H__ */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* File : cache_init.S
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#include "../common/mips.inc"
|
||||||
|
#include "../common/mipsregs.h"
|
||||||
|
#include "../common/stackframe.h"
|
||||||
|
|
||||||
|
.text
|
||||||
|
.set noreorder
|
||||||
|
|
||||||
|
.globl cache_init
|
||||||
|
.ent cache_init
|
||||||
|
cache_init:
|
||||||
|
.set noreorder
|
||||||
|
mtc0 zero, CP0_TAGLO
|
||||||
|
move t0, a0 // cache total size
|
||||||
|
move t1, a1 // cache line size
|
||||||
|
li t2, 0x80000000
|
||||||
|
addu t3, t0, t2
|
||||||
|
|
||||||
|
_cache_init_loop:
|
||||||
|
cache 8, 0(t2) // icache_index_store_tag
|
||||||
|
cache 9, 0(t2) // dcache_index_store_tag
|
||||||
|
addu t2, t1
|
||||||
|
bne t2, t3, _cache_init_loop
|
||||||
|
nop
|
||||||
|
|
||||||
|
mfc0 t0, CP0_CONFIG
|
||||||
|
li t1, 0x7
|
||||||
|
not t1
|
||||||
|
and t0, t0, t1
|
||||||
|
or t0, 0x3 // cacheable, noncoherent, write-back, write allocate
|
||||||
|
mtc0 t0, CP0_CONFIG
|
||||||
|
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.set reorder
|
||||||
|
.end cache_init
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* File : context_gcc.S
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#include "../common/mips.inc"
|
||||||
|
#include "../common/stackframe.h"
|
||||||
|
#include "jz47xx.h"
|
||||||
|
|
||||||
|
.section ".text", "ax"
|
||||||
|
.set noreorder
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rt_base_t rt_hw_interrupt_disable()
|
||||||
|
*/
|
||||||
|
.globl rt_hw_interrupt_disable
|
||||||
|
rt_hw_interrupt_disable:
|
||||||
|
mfc0 v0, CP0_STATUS
|
||||||
|
and v1, v0, 0xfffffffe
|
||||||
|
mtc0 v1, CP0_STATUS
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void rt_hw_interrupt_enable(rt_base_t level)
|
||||||
|
*/
|
||||||
|
.globl rt_hw_interrupt_enable
|
||||||
|
rt_hw_interrupt_enable:
|
||||||
|
mtc0 a0, CP0_STATUS
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
|
||||||
|
* a0 --> from
|
||||||
|
* a1 --> to
|
||||||
|
*/
|
||||||
|
.globl rt_hw_context_switch
|
||||||
|
rt_hw_context_switch:
|
||||||
|
mtc0 ra, CP0_EPC
|
||||||
|
SAVE_ALL
|
||||||
|
|
||||||
|
sw sp, 0(a0) /* store sp in preempted tasks TCB */
|
||||||
|
lw sp, 0(a1) /* get new task stack pointer */
|
||||||
|
|
||||||
|
RESTORE_ALL_AND_RET
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void rt_hw_context_switch_to(rt_uint32 to)/*
|
||||||
|
* a0 --> to
|
||||||
|
*/
|
||||||
|
.globl rt_hw_context_switch_to
|
||||||
|
rt_hw_context_switch_to:
|
||||||
|
lw sp, 0(a0) /* get new task stack pointer */
|
||||||
|
|
||||||
|
RESTORE_ALL_AND_RET
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
|
||||||
|
*/
|
||||||
|
.globl rt_thread_switch_interrput_flag
|
||||||
|
.globl rt_interrupt_from_thread
|
||||||
|
.globl rt_interrupt_to_thread
|
||||||
|
.globl rt_hw_context_switch_interrupt
|
||||||
|
rt_hw_context_switch_interrupt:
|
||||||
|
la t0, rt_thread_switch_interrput_flag
|
||||||
|
lw t1, 0(t0)
|
||||||
|
nop
|
||||||
|
bnez t1, _reswitch
|
||||||
|
nop
|
||||||
|
li t1, 0x01 /* set rt_thread_switch_interrput_flag to 1 */
|
||||||
|
sw t1, 0(t0)
|
||||||
|
la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
|
||||||
|
sw a0, 0(t0)
|
||||||
|
_reswitch:
|
||||||
|
la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
|
||||||
|
sw a1, 0(t0)
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void rt_hw_context_switch_interrupt_do(rt_base_t flag)
|
||||||
|
*/
|
||||||
|
.globl rt_interrupt_enter
|
||||||
|
.globl rt_interrupt_leave
|
||||||
|
.globl mips_irq_handle
|
||||||
|
mips_irq_handle:
|
||||||
|
SAVE_ALL
|
||||||
|
|
||||||
|
mfc0 t0, CP0_CAUSE
|
||||||
|
mfc0 t1, CP0_STATUS
|
||||||
|
and t0, t1
|
||||||
|
|
||||||
|
andi t0, 0xff00
|
||||||
|
beqz t0, spurious_interrupt
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* switch to kernel stack */
|
||||||
|
move k0, sp
|
||||||
|
li sp, SYSTEM_STACK
|
||||||
|
addiu sp, sp, -4
|
||||||
|
sw k0, 0(sp)
|
||||||
|
|
||||||
|
1:
|
||||||
|
jal rt_interrupt_enter
|
||||||
|
nop
|
||||||
|
jal rt_interrupt_dispatch
|
||||||
|
nop
|
||||||
|
jal rt_interrupt_leave
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* switch sp back to thread's context */
|
||||||
|
lw k0, 0(sp)
|
||||||
|
nop
|
||||||
|
move sp, k0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if rt_thread_switch_interrput_flag set, jump to
|
||||||
|
* rt_hw_context_switch_interrupt_do and don't return
|
||||||
|
*/
|
||||||
|
la k0, rt_thread_switch_interrput_flag
|
||||||
|
lw k1, 0(k0)
|
||||||
|
beqz k1, spurious_interrupt
|
||||||
|
nop
|
||||||
|
|
||||||
|
/*
|
||||||
|
* switch to the new thread
|
||||||
|
*/
|
||||||
|
sw zero, 0(k0) /* clear flag */
|
||||||
|
la k0, rt_interrupt_from_thread
|
||||||
|
lw k1, 0(k0)
|
||||||
|
nop
|
||||||
|
sw sp, 0(k1) /* store sp in preempted tasks's TCB */
|
||||||
|
la k0, rt_interrupt_to_thread
|
||||||
|
lw k1, 0(k0)
|
||||||
|
nop
|
||||||
|
lw sp, 0(k1) /* get new task's stack pointer */
|
||||||
|
j spurious_interrupt
|
||||||
|
nop
|
||||||
|
|
||||||
|
spurious_interrupt:
|
||||||
|
RESTORE_ALL_AND_RET
|
||||||
|
|
||||||
|
.set reorder
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* File : cpu.c
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-07-09 Bernard first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup Jz47xx
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this function will reset CPU
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void rt_hw_cpu_reset()
|
||||||
|
{
|
||||||
|
/* open the watch-dog */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this function will shutdown CPU
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void rt_hw_cpu_shutdown()
|
||||||
|
{
|
||||||
|
rt_kprintf("shutdown...\n");
|
||||||
|
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* File : exception.c
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rthw.h>
|
||||||
|
#include "../common/exception.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup Jz47xx
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exception handle table
|
||||||
|
*/
|
||||||
|
exception_func_t sys_exception_handlers[33];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setup the exception handle
|
||||||
|
*/
|
||||||
|
exception_func_t rt_set_except_vector(int n, exception_func_t func)
|
||||||
|
{
|
||||||
|
exception_func_t old_handler = sys_exception_handlers[n];
|
||||||
|
|
||||||
|
if ((n == 0) || (n > 32) || (!func))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_exception_handlers[n] = func;
|
||||||
|
|
||||||
|
return old_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tlbmiss_handle(rt_uint32_t epc)
|
||||||
|
{
|
||||||
|
rt_kprintf("tlb-miss happens, epc: 0x%08x\n", epc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unhandled_exception_handle(pt_regs_t *regs)
|
||||||
|
{
|
||||||
|
rt_kprintf("exception happens, epc: 0x%08x\n", regs->cp0_epc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void install_default_execpt_handle(void)
|
||||||
|
{
|
||||||
|
rt_int32_t i;
|
||||||
|
|
||||||
|
for (i=0; i<33; i++)
|
||||||
|
sys_exception_handlers[i] = (exception_func_t)unhandled_exception_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* File : interrupt.c
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-07-09 Bernard first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "jz47xx.h"
|
||||||
|
#include "interrupt.h"
|
||||||
|
|
||||||
|
#define JZ47XX_MAX_INTR 32
|
||||||
|
|
||||||
|
extern rt_uint32_t rt_interrupt_nest;
|
||||||
|
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
|
||||||
|
rt_uint32_t rt_thread_switch_interrput_flag;
|
||||||
|
|
||||||
|
static rt_isr_handler_t irq_handle_table[JZ47XX_MAX_INTR];
|
||||||
|
|
||||||
|
extern rt_uint32_t cp0_get_cause(void);
|
||||||
|
extern rt_uint32_t cp0_get_status(void);
|
||||||
|
extern void disable_cp0_counter(void);
|
||||||
|
extern void enable_cp0_counter(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup Jz47xx
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
|
||||||
|
void rt_hw_interrupt_handler(int vector)
|
||||||
|
{
|
||||||
|
rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will initialize hardware interrupt
|
||||||
|
*/
|
||||||
|
void rt_hw_interrupt_init()
|
||||||
|
{
|
||||||
|
rt_int32_t index;
|
||||||
|
|
||||||
|
for (index = 0; index < JZ47XX_MAX_INTR; index ++)
|
||||||
|
{
|
||||||
|
irq_handle_table[index] = (rt_isr_handler_t)rt_hw_interrupt_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* init interrupt nest, and context in thread sp */
|
||||||
|
rt_interrupt_nest = 0;
|
||||||
|
rt_interrupt_from_thread = 0;
|
||||||
|
rt_interrupt_to_thread = 0;
|
||||||
|
rt_thread_switch_interrput_flag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will mask a interrupt.
|
||||||
|
* @param vector the interrupt number
|
||||||
|
*/
|
||||||
|
void rt_hw_interrupt_mask(int vector)
|
||||||
|
{
|
||||||
|
/* mask interrupt */
|
||||||
|
INTC_IMSR = 1 << vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will un-mask a interrupt.
|
||||||
|
* @param vector the interrupt number
|
||||||
|
*/
|
||||||
|
void rt_hw_interrupt_umask(int vector)
|
||||||
|
{
|
||||||
|
INTC_IMCR = 1 << vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will install a interrupt service routine to a interrupt.
|
||||||
|
* @param vector the interrupt number
|
||||||
|
* @param new_handler the interrupt service routine to be installed
|
||||||
|
* @param old_handler the old interrupt service routine
|
||||||
|
*/
|
||||||
|
void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
|
||||||
|
{
|
||||||
|
if (vector >= 0 && vector < JZ47XX_MAX_INTR)
|
||||||
|
{
|
||||||
|
if (old_handler != RT_NULL)
|
||||||
|
*old_handler = irq_handle_table[vector];
|
||||||
|
if (new_handler != RT_NULL)
|
||||||
|
irq_handle_table[vector] = (rt_isr_handler_t)new_handler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rt_interrupt_dispatch(void *ptreg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
rt_uint32_t pending;
|
||||||
|
rt_isr_handler_t irq_func;
|
||||||
|
|
||||||
|
/* the hardware interrupt */
|
||||||
|
pending = INTC_IPR;
|
||||||
|
if (!pending) return;
|
||||||
|
|
||||||
|
for (i = 0; i < JZ47XX_MAX_INTR; i++)
|
||||||
|
{
|
||||||
|
if ((pending & (1<<i)))
|
||||||
|
{
|
||||||
|
pending &= ~(1<<i);
|
||||||
|
irq_func = irq_handle_table[i];
|
||||||
|
|
||||||
|
/* do interrupt */
|
||||||
|
(*irq_func)(i);
|
||||||
|
|
||||||
|
/* ack interrupt */
|
||||||
|
INTC_IPR = 1 << i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@}*/
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* File : interrupt.h
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#ifndef __IRQ_H__
|
||||||
|
#define __IRQ_H__
|
||||||
|
|
||||||
|
|
||||||
|
/* Interrupt Numbers */
|
||||||
|
#define AXXXX_UART_INT 0
|
||||||
|
#define AXXXX_USB_INT 1
|
||||||
|
#define AXXXX_RTC_INT 2
|
||||||
|
#define AXXXX_DMA_INT 3
|
||||||
|
#define AXXXX_EXTERNAL_INT 4
|
||||||
|
#define AXXXX_SPI_INT 5
|
||||||
|
#define AXXXX_I2C1_INT 6
|
||||||
|
#define AXXXX_I2C2_INT 7
|
||||||
|
#define AXXXX_ADC_INT 8
|
||||||
|
#define AXXXX_DAC_INT 9
|
||||||
|
#define AXXXX_FLASH_INT 10
|
||||||
|
|
||||||
|
#define AXXXX_CP0_COUNT_INT 11
|
||||||
|
#define AXXXX_MAX_INTR 12
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* end of __IRQ_H__ */
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#ifndef __JZ4755_H__
|
||||||
|
#define __JZ4755_H__
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#ifndef __JZ47XX_H__
|
||||||
|
#define __JZ47XX_H__
|
||||||
|
|
||||||
|
#define __REG8(addr) *((volatile unsigned char *)(addr))
|
||||||
|
#define __REG16(addr) *((volatile unsigned short *)(addr))
|
||||||
|
#define __REG32(addr) *((volatile unsigned int *)(addr))
|
||||||
|
|
||||||
|
#define HARB_BASE 0xB3000000
|
||||||
|
#define EMC_BASE 0xB3010000
|
||||||
|
#define DMAC_BASE 0xB3020000
|
||||||
|
#define UHC_BASE 0xB3030000
|
||||||
|
#define UDC_BASE 0xB3040000
|
||||||
|
#define LCD_BASE 0xB3050000
|
||||||
|
#define CIM_BASE 0xB3060000
|
||||||
|
#define ETH_BASE 0xB3100000
|
||||||
|
#define NBM_BASE 0xB3F00000
|
||||||
|
|
||||||
|
#define CPM_BASE 0xB0000000
|
||||||
|
#define INTC_BASE 0xB0001000
|
||||||
|
#define OST_BASE 0xB0002000
|
||||||
|
#define RTC_BASE 0xB0003000
|
||||||
|
#define WDT_BASE 0xB0004000
|
||||||
|
#define GPIO_BASE 0xB0010000
|
||||||
|
#define AIC_BASE 0xB0020000
|
||||||
|
#define MSC_BASE 0xB0021000
|
||||||
|
#define UART0_BASE 0xB0030000
|
||||||
|
#define UART1_BASE 0xB0031000
|
||||||
|
#define UART2_BASE 0xB0032000
|
||||||
|
#define UART3_BASE 0xB0033000
|
||||||
|
#define FIR_BASE 0xB0040000
|
||||||
|
#define SCC_BASE 0xB0041000
|
||||||
|
#define SCC0_BASE 0xB0041000
|
||||||
|
#define I2C_BASE 0xB0042000
|
||||||
|
#define SSI_BASE 0xB0043000
|
||||||
|
#define SCC1_BASE 0xB0044000
|
||||||
|
#define PWM0_BASE 0xB0050000
|
||||||
|
#define PWM1_BASE 0xB0051000
|
||||||
|
#define DES_BASE 0xB0060000
|
||||||
|
#define UPRT_BASE 0xB0061000
|
||||||
|
#define KBC_BASE 0xB0062000
|
||||||
|
|
||||||
|
/* uart offset */
|
||||||
|
#define UART_RDR(base) __REG8((base) + 0x00) /* R 8b H'xx */
|
||||||
|
#define UART_TDR(base) __REG8((base) + 0x00) /* W 8b H'xx */
|
||||||
|
#define UART_DLLR(base) __REG8((base) + 0x00) /* RW 8b H'00 */
|
||||||
|
#define UART_DLHR(base) __REG8((base) + 0x04) /* RW 8b H'00 */
|
||||||
|
#define UART_IER(base) __REG8((base) + 0x04) /* RW 8b H'00 */
|
||||||
|
#define UART_ISR(base) __REG8((base) + 0x08) /* R 8b H'01 */
|
||||||
|
#define UART_FCR(base) __REG8((base) + 0x08) /* W 8b H'00 */
|
||||||
|
#define UART_LCR(base) __REG8((base) + 0x0C) /* RW 8b H'00 */
|
||||||
|
#define UART_MCR(base) __REG8((base) + 0x10) /* RW 8b H'00 */
|
||||||
|
#define UART_LSR(base) __REG8((base) + 0x14) /* R 8b H'00 */
|
||||||
|
#define UART_MSR(base) __REG8((base) + 0x18) /* R 8b H'00 */
|
||||||
|
#define UART_SPR(base) __REG8((base) + 0x1C) /* RW 8b H'00 */
|
||||||
|
#define UART_MCR(base) __REG8((base) + 0x10) /* RW 8b H'00 */
|
||||||
|
#define UART_SIRCR(base) __REG8((base) + 0x20) /* RW 8b H'00 */
|
||||||
|
|
||||||
|
/* interrupt controller */
|
||||||
|
#define INTC_ISR __REG32(INTC_BASE + 0x00)
|
||||||
|
#define INTC_IMR __REG32(INTC_BASE + 0x04)
|
||||||
|
#define INTC_IMSR __REG32(INTC_BASE + 0x08)
|
||||||
|
#define INTC_IMCR __REG32(INTC_BASE + 0x0c)
|
||||||
|
#define INTC_IPR __REG32(INTC_BASE + 0x10)
|
||||||
|
|
||||||
|
#define IRQ_I2C 1
|
||||||
|
#define IRQ_PS2 2
|
||||||
|
#define IRQ_UPRT 3
|
||||||
|
#define IRQ_CORE 4
|
||||||
|
#define IRQ_UART3 6
|
||||||
|
#define IRQ_UART2 7
|
||||||
|
#define IRQ_UART1 8
|
||||||
|
#define IRQ_UART0 9
|
||||||
|
#define IRQ_SCC1 10
|
||||||
|
#define IRQ_SCC0 11
|
||||||
|
#define IRQ_UDC 12
|
||||||
|
#define IRQ_UHC 13
|
||||||
|
#define IRQ_MSC 14
|
||||||
|
#define IRQ_RTC 15
|
||||||
|
#define IRQ_FIR 16
|
||||||
|
#define IRQ_SSI 17
|
||||||
|
#define IRQ_CIM 18
|
||||||
|
#define IRQ_ETH 19
|
||||||
|
#define IRQ_AIC 20
|
||||||
|
#define IRQ_DMAC 21
|
||||||
|
#define IRQ_OST2 22
|
||||||
|
#define IRQ_OST1 23
|
||||||
|
#define IRQ_OST0 24
|
||||||
|
#define IRQ_GPIO3 25
|
||||||
|
#define IRQ_GPIO2 26
|
||||||
|
#define IRQ_GPIO1 27
|
||||||
|
#define IRQ_GPIO0 28
|
||||||
|
#define IRQ_LCD 30
|
||||||
|
|
||||||
|
#define SYSTEM_STACK 0x8000ffe8 /* the kernel system stack address */
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* File : mipscfg.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-27 swkyer first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "../common/mipsregs.h"
|
||||||
|
#include "../common/mipscfg.h"
|
||||||
|
|
||||||
|
mips32_core_cfg_t g_mips_core =
|
||||||
|
{
|
||||||
|
16, /* icache_line_size */
|
||||||
|
256, /* icache_lines_per_way */
|
||||||
|
4, /* icache_ways */
|
||||||
|
16, /* dcache_line_size */
|
||||||
|
256, /* dcache_lines_per_way */
|
||||||
|
4, /* dcache_ways */
|
||||||
|
16, /* max_tlb_entries */
|
||||||
|
};
|
||||||
|
|
||||||
|
static rt_uint16_t m_pow(rt_uint16_t b, rt_uint16_t n)
|
||||||
|
{
|
||||||
|
rt_uint16_t rets = 1;
|
||||||
|
|
||||||
|
while (n--)
|
||||||
|
rets *= b;
|
||||||
|
|
||||||
|
return rets;
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_uint16_t m_log2(rt_uint16_t b)
|
||||||
|
{
|
||||||
|
rt_uint16_t rets = 0;
|
||||||
|
|
||||||
|
while (b != 1)
|
||||||
|
{
|
||||||
|
b /= 2;
|
||||||
|
rets++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read core attribute
|
||||||
|
*/
|
||||||
|
void mips32_cfg_init(void)
|
||||||
|
{
|
||||||
|
rt_uint16_t val;
|
||||||
|
rt_uint32_t cp0_config1;
|
||||||
|
|
||||||
|
cp0_config1 = read_c0_config();
|
||||||
|
if (cp0_config1 & 0x80000000)
|
||||||
|
{
|
||||||
|
cp0_config1 = read_c0_config1();
|
||||||
|
|
||||||
|
val = (cp0_config1 & (7<<22))>>22;
|
||||||
|
g_mips_core.icache_lines_per_way = 64 * m_pow(2, val);
|
||||||
|
val = (cp0_config1 & (7<<19))>>19;
|
||||||
|
g_mips_core.icache_line_size = 2 * m_pow(2, val);
|
||||||
|
val = (cp0_config1 & (7<<16))>>16;
|
||||||
|
g_mips_core.icache_ways = val + 1;
|
||||||
|
|
||||||
|
val = (cp0_config1 & (7<<13))>>13;
|
||||||
|
g_mips_core.dcache_lines_per_way = 64 * m_pow(2, val);
|
||||||
|
val = (cp0_config1 & (7<<10))>>10;
|
||||||
|
g_mips_core.dcache_line_size = 2 * m_pow(2, val);
|
||||||
|
val = (cp0_config1 & (7<<7))>>7;
|
||||||
|
g_mips_core.dcache_ways = val + 1;
|
||||||
|
|
||||||
|
val = (cp0_config1 & (0x3F<<25))>>25;
|
||||||
|
g_mips_core.max_tlb_entries = val + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* File : stack.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
* 2010-07-07 Bernard porting to Jz47xx
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup Jz47xx
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
|
||||||
|
extern rt_uint32_t cp0_get_cause(void);
|
||||||
|
extern rt_uint32_t cp0_get_status(void);
|
||||||
|
extern rt_uint32_t cp0_get_hi(void);
|
||||||
|
extern rt_uint32_t cp0_get_lo(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will initialize thread stack
|
||||||
|
*
|
||||||
|
* @param tentry the entry of thread
|
||||||
|
* @param parameter the parameter of entry
|
||||||
|
* @param stack_addr the beginning stack address
|
||||||
|
* @param texit the function will be called when thread exit
|
||||||
|
*
|
||||||
|
* @return stack address
|
||||||
|
*/
|
||||||
|
rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *stack_addr, void *texit)
|
||||||
|
{
|
||||||
|
rt_uint32_t *stk;
|
||||||
|
static rt_uint32_t g_sr = 0;
|
||||||
|
|
||||||
|
if (g_sr == 0)
|
||||||
|
{
|
||||||
|
g_sr = cp0_get_status();
|
||||||
|
g_sr &= 0xfffffffe;
|
||||||
|
g_sr |= 0x8403;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Start at stack top */
|
||||||
|
stk = (rt_uint32_t *)stack_addr;
|
||||||
|
*(stk) = (rt_uint32_t) tentry; /* pc: Entry Point */
|
||||||
|
*(--stk) = (rt_uint32_t) 0xeeee; /* c0_cause */
|
||||||
|
*(--stk) = (rt_uint32_t) 0xffff; /* c0_badvaddr */
|
||||||
|
*(--stk) = (rt_uint32_t) cp0_get_lo(); /* lo */
|
||||||
|
*(--stk) = (rt_uint32_t) cp0_get_hi(); /* hi */
|
||||||
|
*(--stk) = (rt_uint32_t) g_sr; /* C0_SR: HW2 = En, IE = En */
|
||||||
|
*(--stk) = (rt_uint32_t) texit; /* ra */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000001e; /* s8 */
|
||||||
|
*(--stk) = (rt_uint32_t) stack_addr; /* sp */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000001c; /* gp */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000001b; /* k1 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000001a; /* k0 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000019; /* t9 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000018; /* t8 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000017; /* s7 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000016; /* s6 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000015; /* s5 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000014; /* s4 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000013; /* s3 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000012; /* s2 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000011; /* s1 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000010; /* s0 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000f; /* t7 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000e; /* t6 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000d; /* t5 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000c; /* t4 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000b; /* t3 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x0000000a; /* t2 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000009; /* t1 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000008; /* t0 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000007; /* a3 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000006; /* a2 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000005; /* a1 */
|
||||||
|
*(--stk) = (rt_uint32_t) parameter; /* a0 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000003; /* v1 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000002; /* v0 */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000001; /* at */
|
||||||
|
*(--stk) = (rt_uint32_t) 0x00000000; /* zero */
|
||||||
|
|
||||||
|
/* return task's current stack address */
|
||||||
|
return (rt_uint8_t *)stk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@}*/
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* File : start_gcc.S
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2010-05-17 swkyer first version
|
||||||
|
*/
|
||||||
|
#include "../common/mips.inc"
|
||||||
|
#include "../common/stackframe.h"
|
||||||
|
#include "jz47xx.h"
|
||||||
|
|
||||||
|
.section ".start", "ax"
|
||||||
|
.set noreorder
|
||||||
|
|
||||||
|
.extern sys_exception_handlers
|
||||||
|
.extern tlbmiss_handle
|
||||||
|
|
||||||
|
.globl _entry
|
||||||
|
/* exception entry */
|
||||||
|
_entry:
|
||||||
|
.org 0x0
|
||||||
|
.set noreorder
|
||||||
|
mfc0 t0, $14
|
||||||
|
jal tlbmiss_handle
|
||||||
|
move a0, t0
|
||||||
|
j _sys_dead /* TLB Miss, should never happen */
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void config_tick_timer(uint32_t perio)
|
||||||
|
*/
|
||||||
|
.globl config_tick_timer
|
||||||
|
config_tick_timer:
|
||||||
|
mfc0 t0, $9 /* count */
|
||||||
|
nop
|
||||||
|
addu t1, t0, a0
|
||||||
|
mtc0 t1, $11 /* compare */
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.globl cp0_get_cause
|
||||||
|
cp0_get_cause:
|
||||||
|
mfc0 v0, CP0_CAUSE
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.globl cp0_get_status
|
||||||
|
cp0_get_status:
|
||||||
|
mfc0 v0, CP0_STATUS
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.globl cp0_get_hi
|
||||||
|
cp0_get_hi:
|
||||||
|
mfhi v0
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.globl cp0_get_lo
|
||||||
|
cp0_get_lo:
|
||||||
|
mflo v0
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
|
||||||
|
.org 0x100
|
||||||
|
.set noreorder
|
||||||
|
j _sys_dead /* cache error exception handle */
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
|
||||||
|
.globl disable_cp0_counter
|
||||||
|
disable_cp0_counter:
|
||||||
|
.set noreorder
|
||||||
|
mfc0 t0, CP0_CAUSE
|
||||||
|
lui t1, 0x0800
|
||||||
|
or t0, t1
|
||||||
|
mtc0 t0, CP0_CAUSE
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
.globl enable_cp0_counter
|
||||||
|
enable_cp0_counter:
|
||||||
|
.set noreorder
|
||||||
|
mfc0 t0, CP0_CAUSE
|
||||||
|
lui t1, 0x0800
|
||||||
|
not t2, t1
|
||||||
|
and t0, t0, t2
|
||||||
|
mtc0 t0, CP0_CAUSE
|
||||||
|
jr ra
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
// general exception handle
|
||||||
|
.org 0x180
|
||||||
|
_gen_exp_handle:
|
||||||
|
.set noreorder
|
||||||
|
mfc0 k1, CP0_CAUSE
|
||||||
|
andi k1, k1, 0x7c
|
||||||
|
srl k1, k1, 2
|
||||||
|
lw k0, sys_exception_handlers(k1)
|
||||||
|
jr k0
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
/* error happens */
|
||||||
|
_sys_dead:
|
||||||
|
.set noreorder
|
||||||
|
jal rt_hw_cpu_reset
|
||||||
|
nop
|
||||||
|
/* should never return here */
|
||||||
|
j _sys_dead
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
|
||||||
|
.globl mips_irq_handle
|
||||||
|
/* interrupt handle */
|
||||||
|
.org 0x200
|
||||||
|
_irq_handle:
|
||||||
|
.set noreorder
|
||||||
|
la k0, mips_irq_handle
|
||||||
|
jr k0
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
|
|
||||||
|
|
||||||
|
/* the REAL program entry */
|
||||||
|
.extern mips32_cfg_init
|
||||||
|
.extern r4k_cache_init
|
||||||
|
.extern install_default_execpt_handle
|
||||||
|
.globl _start
|
||||||
|
.org 0x400
|
||||||
|
_start:
|
||||||
|
.set noreorder
|
||||||
|
la ra, _start
|
||||||
|
|
||||||
|
/* init cp0 registers. */
|
||||||
|
li t0, 0x0040FC00
|
||||||
|
mtc0 t0, CP0_STATUS
|
||||||
|
|
||||||
|
li t1, 0x00800000
|
||||||
|
mtc0 t1, CP0_CAUSE
|
||||||
|
|
||||||
|
/* setup stack pointer */
|
||||||
|
li sp, SYSTEM_STACK
|
||||||
|
la gp, _gp
|
||||||
|
|
||||||
|
/* clear bss */
|
||||||
|
la t0, __bss_start
|
||||||
|
la t1, __bss_end
|
||||||
|
_clr_bss_loop:
|
||||||
|
sw zero, 0(t0)
|
||||||
|
bne t0, t1, _clr_bss_loop
|
||||||
|
addiu t0, t0, 4
|
||||||
|
|
||||||
|
/* read core config */
|
||||||
|
jal mips32_cfg_init
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* initialize cache */
|
||||||
|
jal r4k_cache_init
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* setup default exception handle */
|
||||||
|
jal install_default_execpt_handle
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* jump to RT-Thread RTOS */
|
||||||
|
jal rtthread_startup
|
||||||
|
nop
|
||||||
|
|
||||||
|
/* restart, never die */
|
||||||
|
j _start
|
||||||
|
nop
|
||||||
|
.set reorder
|
||||||
Reference in New Issue
Block a user