zoukankan      html  css  js  c++  java
  • 异常向量表设计

    在ARM Architecture Reference Manual-A2.6章节给了明确的定义

    异常:因为内部或者外部的一些事件,导致处理器停下正在处理的工作,转而去处理这些发生的事件

    异常向量:当一种异常发生的时候,ARM处理器会跳转,到对应该异常的固定地址去执行异常处理程序,而这个固定的地址,就称异常向量

    起始文件start.c

    .text
    .global _start
    _start:
    	b reset
    	ldr pc, _undefined_instruction
    	ldr pc, _software_interrupt
    	ldr pc, _prefetch_abort
    	ldr pc, _data_abort
    	ldr pc, _not_used
    	ldr pc, _irq
    	ldr pc, _fiq
    
    _undefined_instruction: .word undefined_instruction
    _software_interrupt:.word software_interrupt
    _prefetch_abort:.word prefetch_abort
    _data_abort:.word data_abort
    _not_used:.word not_used
    _irq:.word irq
    _fiq:.word fiq
    
    undefined_instruction:
    	nop
    	
    software_interrupt:
    	nop
    
    prefetch_abort:
    	nop
    	
    data_abort:
    	nop
    	
    not_used:
    	nop
    	
    irq:
    	nop
    	
    fiq:
    	nop
    
    reset:
    	nop
    

      

    链接器脚本文件gboot.lds

    OUTPUT_ARCH(arm) 
    ENTRY(_start) 
    SECTIONS{ 
    	. = 0x30008000;
    
            . = ALIGN(4); 
    	.text : 
    	{ 
    	start.o(.text) 
    	*(.text) 
    	}
                                                  
    	. = ALIGN(4); 
    	.data : 
    	{ 
    	*(.data) 
    	}
    
    	. = ALIGN(4); 
    	bss_start = . ; 
    	.bss : 
    	{
    	*(.bss)
    	}
    	bss_end = . ;
    }
    

    makefile文件

    all : start.o
    	arm-linux-ld -Tgboot.lds -o gboot.elf $^
    	arm-linux-objcopy -O binary gboot.elf gboot.bin
    	
    %.o : %.S
    	arm-linux-gcc -g -c $^
    	
    %.o : %.c
    	arm-linux-gcc -g -c $^
    	
    .PHONY: clean
    clean:
    	rm *.o *.elf *.bin
    

    2440赫尔6410的异常向量表就是这样

    210还需要加一个起始头文件,代码如下,是计算校验和的

      1 /* 在BL0阶段,Irom内固化的代码读取nandflash或SD卡前16K的内容,
      2  * 并比对前16字节中的校验和是否正确,正确则继续,错误则停止。
      3  */
      4 #include <stdio.h>
      5 #include <string.h>
      6 #include <stdlib.h>
      7 
      8 #define BUFSIZE                 (16*1024)
      9 #define IMG_SIZE                (16*1024)
     10 #define SPL_HEADER_SIZE         16
     11 #define SPL_HEADER              "S5PC110 HEADER  "
     12 
     13 int main (int argc, char *argv[])
     14 {
     15     FILE        *fp;
     16     char        *Buf, *a;
     17     int        BufLen;
     18     int        nbytes, fileLen;
     19     unsigned int    checksum, count;
     20     int        i;
     21     
     22     // 1. 3个参数
     23     if (argc != 3)
     24     {
     25         printf("Usage: mkbl1 <source file> <destination file>
    ");
     26         return -1;
     27     }
     28 
     29     // 2. 分配16K的buffer
     30     BufLen = BUFSIZE;
     31     Buf = (char *)malloc(BufLen);
     32     if (!Buf)
     33     {
     34         printf("Alloc buffer failed!
    ");
     35         return -1;
     36     }
     37 
     38     memset(Buf, 0x00, BufLen);
     39 
     40     // 3. 读源bin到buffer
     41     // 3.1 打开源bin
     42     fp = fopen(argv[1], "rb");
     43     if( fp == NULL)
     44     {
     45         printf("source file open error
    ");
     46         free(Buf);
     47         return -1;
     48     }
     49     // 3.2 获取源bin长度
     50     fseek(fp, 0L, SEEK_END);
     51     fileLen = ftell(fp);
     52     fseek(fp, 0L, SEEK_SET);
     53     // 3.3 源bin长度不得超过16K-16byte
     54     count = (fileLen < (IMG_SIZE - SPL_HEADER_SIZE))
     55         ? fileLen : (IMG_SIZE - SPL_HEADER_SIZE);
     56     // 3.4 buffer[0~15]存放"S5PC110 HEADER  "
     57     memcpy(&Buf[0], SPL_HEADER, SPL_HEADER_SIZE);
     58     // 3.5 读源bin到buffer[16]
     59     nbytes = fread(Buf + SPL_HEADER_SIZE, 1, count, fp);
     60     if ( nbytes != count )
     61     {
     62         printf("source file read error
    ");
     63         free(Buf);
     64         fclose(fp);
     65         return -1;
     66     }
     67     fclose(fp);
     68 
     69     // 4. 计算校验和
     70      // 4.1 从第16byte开始统计buffer中共有几个1
     71     a = Buf + SPL_HEADER_SIZE;
     72     for(i = 0, checksum = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
     73         checksum += (0x000000FF) & *a++;
     74     // 4.2 将校验和保存在buffer[8~15]
     75     a = Buf + 8;
     76     *( (unsigned int *)a ) = checksum;
     77 
     78     // 5. 拷贝buffer中的内容到目的bin
     79     // 5.1 打开目的bin
     80     fp = fopen(argv[2], "wb");
     81     if (fp == NULL)
     82     {
     83         printf("destination file open error
    ");
     84         free(Buf);
     85         return -1;
     86     }
     87     // 5.2 将16k的buffer拷贝到目的bin中
     88     a = Buf;
     89     nbytes    = fwrite( a, 1, BufLen, fp);
     90     if ( nbytes != BufLen )
     91     {
     92         printf("destination file write error
    ");
     93         free(Buf);
     94         fclose(fp);
     95         return -1;
     96     }
     97 
     98     free(Buf);
     99     fclose(fp);
    100 
    101     return 0;
    102 }
  • 相关阅读:
    Ubuntu 14.04 LTS 系统空间不足,输入密码后,无法进入桌面的解决办法
    语言代码表
    在WPS中删除整行的快捷键是什么?
    Google浏览器&插件
    Linux命令大全
    Python下载安装
    Tiobe最新编程语言排行
    windows 清理利器
    如何用VBA实现格式刷的功能?
    武侠音乐精装
  • 原文地址:https://www.cnblogs.com/sanshijvshi/p/8331600.html
Copyright © 2011-2022 走看看