内核运行之前访问IO

如果要在内核运行之前访问CPU的某些IO端口,直接使用指针方式定义寄存器进行操作即可。例如,在解压内核的时候喂狗,通过操作IO进行,可以这样操作:

在arch/arm/boot/compressed/misc.c文件:
 
    307     arch_decomp_setup();
    308
    309     makecrc();
    310     *((volatile unsigned long *)0x40E00054) &= (~(3<<28)); //ABING GPAF0_L
    311     *((volatile unsigned long *)0x40E0001C) = (1<<14); //ABING GPDR0
    312     *((volatile unsigned long *)0x40E00024) = (1<<14); //ABING GPCR0
    313     putstr("Uncompressing Linux...");
    314     *((volatile unsigned long *)0x40E00018) = (1<<14); //ABING GPSR0
    315     gunzip();
    316     *((volatile unsigned long *)0x40E00024) = (1<<14); //ABING GPCR0
    317     putstr(" done, booting the kernel.\n");
    318     return output_ptr;
 
 
 
 
参考include/asm-arm/arch-pxa/uncompress.h文件访问串口的代码:
  12#define FFUART          ((volatile unsigned long *)0x40100000)
  13#define BTUART          ((volatile unsigned long *)0x40200000)
  14#define STUART          ((volatile unsigned long *)0x40700000)
  15
  16#define UART            FFUART
  17
  18
  19static __inline__ void putc(char c)
  20{
  21        while (!(UART[5] & 0x20));
  22        UART[0] = c;
  23}
  24
  25/*
  26 * This does not append a newline
  27 */
  28static void putstr(const char *s)
  29{
  30        while (*s) {
  31                putc(*s);
  32                if (*s == '\n')
  33                        putc('\r');
  34                s++;
  35        }
  36}
 
   
 
   
可以这样定义:
#define __raw_readl(a)    (*(volatile unsigned int *)(a))
#define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
#define __raw_readw(a)    (*(volatile unsigned short *)(a))
#define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值