int (*printf)(char * ,...) = 0x43e11434;
void (*memcpy)(void *dest, const void *src, int size) = 0x43e25c6c;
void irq_func();
extern unsigned long * my_start;
extern unsigned long * my_end;
#define pwm_base 0x139D0000
#define TCFG0 *(volatile unsigned long *)(pwm_base + 0x0000)
#define TCFG1 *(volatile unsigned long *)(pwm_base + 0x0004)
#define TCON *(volatile unsigned long *)(pwm_base + 0x0008)
#define TCNTB0 *(volatile unsigned long *)(pwm_base + 0x000C)
#define TCMPB0 *(volatile unsigned long *)(pwm_base + 0x0010)
#define TCNTO0 *(volatile unsigned long *)(pwm_base + 0x0014)
#define TCNTB1 *(volatile unsigned long *)(pwm_base + 0x0018)
#define TCMPB1 *(volatile unsigned long *)(pwm_base + 0x001C)
#define TCNTO1 *(volatile unsigned long *)(pwm_base + 0x0020)
#define TCNTB2 *(volatile unsigned long *)(pwm_base + 0x0024)
#define TCMPB2 *(volatile unsigned long *)(pwm_base + 0x0028)
#define TCNTO2 *(volatile unsigned long *)(pwm_base + 0x002C)
#define TCNTB3 *(volatile unsigned long *)(pwm_base + 0x0030)
#define TCMPB3 *(volatile unsigned long *)(pwm_base + 0x0034)
#define TCNTO3 *(volatile unsigned long *)(pwm_base + 0x0038)
#define TCNTB4 *(volatile unsigned long *)(pwm_base + 0x003C)
#define TCNTO4 *(volatile unsigned long *)(pwm_base + 0x0040)
#define TINT_CSTAT *(volatile unsigned long *)(pwm_base + 0x0044)
//step 1
void open_pwm(void);
//step 2 p752
void open_gic(unsigned long irq_num);
void enable_ibit(void);
void init_mmu(void);
void init_table(unsigned long * base);
#define MMU_BASE 0x50000000
#define VEC_BASE 0x51000000
#define FUN_BASE 0x52000000
#define STA_BASE 0x53000000
int main()
{
void * dest = 0x510f0000;
memcpy(dest,my_start,0x10000);
return 0;
volatile unsigned long * gpdcon = 0x114000a0;
*gpdcon &= 0xfffffff0;
*gpdcon |= 0x2;
gpdcon = FUN_BASE;
*gpdcon = irq_func;
printf(" mmu \n");
init_mmu();
printf(" ibit \n");
enable_ibit();
unsigned long irq = 69;
printf(" gic \n");
open_gic(irq);
irq=75;
open_gic(irq);
printf(" pwm \n");
open_pwm();
// wtd_open();
printf("ok \n");
}
void init_table(unsigned long *base)
{
unsigned long phy;
unsigned long vir;
for(vir = 0;vir < 0xffffffff;vir += 0x100000)
{
phy = vir;
base[vir >> 20] = phy | 2 ;
if(0xfff00000 == vir)
break;
}
vir = 0xfff00000;
//vir = 0x0;
phy = VEC_BASE;
base[vir >> 20] = phy | 2;
return ;
}
void init_mmu(void)
{
unsigned long * base = MMU_BASE;
init_table(base);
__asm__(
"mov r0,#0\n"
"mvn r0,r0\n"
"mcr p15,0,r0,c3,c0,0 \n"
"mcr p15,0,%0,c2,c0,0 \n"
"mrc p15,0,r0,c1,c0,0 \n"
"orr r0,r0,#1 \n"
"mov r1,#0x2000\n"
"orr r0,r0,r1\n"
"mcr p15,0,r0,c1,c0,0 \n"
:"+r"(base)
:
:"r0","r1"
);
}
void open_pwm()
{
TCFG0 |= 0x1 | ( 0xfe << 16) ;
TCFG1 &= ~0xf;
TCNTB0 = 50*1000*1000;
TCMPB0 = 25*1000*1000;
TINT_CSTAT = 1;
TCON = (1 << 1);
TCON = 1 |(1 << 2)|(1 << 3);
return ;
}
void open_gic(unsigned long irq)
{
volatile unsigned long * iccicr = 0x10480000;
*iccicr = 1;
volatile unsigned long * iccpmr = 0x10480004;
*iccpmr = 0xff;
volatile unsigned long * icddcr = 0x10490000;
*icddcr = 1;
volatile unsigned long * icdiser = 0x10490100;
icdiser += irq/32;
*icdiser |= (1 << irq%32);
volatile unsigned long *icdipr = 0x10490400;
icdipr += irq/4;
*icdipr &= ~(0xff << (irq%4)*8);
volatile unsigned long *icdiptr = 0x10490800;
icdiptr += irq/4;
*icdiptr &= ~(0xff << (irq%4)*8);
*icdiptr |= (1 << (irq%4)*8);
return ;
}
void enable_ibit(void)
{
__asm__(
"mrs r0,cpsr \n"
"mvn r1,#0x80\n"
"and r0,r0,r1\n"
"msr cpsr,r0 \n"
:
:
:"r0"
);
return ;
}
#define WTCON *(volatile unsigned long *)(0x10060000)
#define WTDAT *(volatile unsigned long *)(0x10060004)
#define WTCNT *(volatile unsigned long *)(0x10060008)
#define WTCLR *(volatile unsigned long *)(0x1006000c)
void wtd_open(void)
{
WTCON = (1 << 2) | ( 3 << 3) | (1 << 5) | (250 << 8);
WTDAT = 31250;
WTCNT = 31250;
}
void irq_func()
{
volatile unsigned long *irq = 0x10490208;
if((*irq) & (1 << 5))
{
printf("pwm irq come in \n");
TINT_CSTAT |= (1 << 5);
return ;
}
printf("other irq \n");
return;
}
__asm__(
"start:\n"
".ascii \"hello\"\n"
".word 0x12345678\n"
".word 0x12345678\n"
"nop \n"
"b undef \n"
"b swi \n"
"nop \n"
"b abort\n"
"nop\n"
"b irq\n"
"undef:\n"
"mov sp,#0x68000000\n"
"stmfd sp!,{r0-r12,lr}\n"
"ldmfd sp,{r0-r12,pc}^\n"
"swi:\n"
"mov sp,#0x68000000\n"
"stmfd sp!,{r0-r12,lr}\n"
"abort:\n"
"mov sp,#0x68000000\n"
"ldmea sp,{r0-r12,pc}^\n"
"mov sp,#0x68000000\n"
"sub lr,lr,#4\n"
"stmfd sp!,{r0-r12,lr} \n"
"mov sp,#0x68000000\n"
"ldmea sp,{r0-r12,pc}^\n"
"irq:\n"
"mov sp,#0x68000000\n"
"sub lr,lr,#4\n"
"stmfd sp!,{r0-r12,lr} \n"
"mov r2,#0x52000000\n"
"ldr r3,[r2]\n"
"blx r3\n"
"mov sp,#0x68000000\n"
"ldmea sp,{r0-r12,pc}^\n"
"end:\n"
"my_start:\n"
".word start\n"
"my_end:\n"
".word end\n"
);