Xilinx SDK中指定变量的物理位置

问题点:使用Xilinx SDK开发 zynq,如果不注意修改堆栈大小,运行会直接卡死崩掉。因为SDK开发属于裸机程序开发了,内存需要自己管理,而带系统的由系统管理。

首先在声明变量的时候在后面增加attribute
int matrix[16][16384] __attribute__((section(".matrix")));

然后在Linker Script里面做如下修改:
1. 双击打开lscript.ld,在GUI的Available Memory Region里面增加需要的内存区域。当然这一步也可以直接用Text Editor编辑lscript.ld完成。

2. 右键单击lscript.ld,单击Open With->Text Editor。在其中增加.matrix的定义。

编辑完成后的lscript.ld 如下所示:
MEMORY
{
   ps7_ddr_0_S_AXI_BASEADDR : ORIGIN = 0x00100000, LENGTH = 0x3FF00000
   ps7_ram_0_S_AXI_BASEADDR : ORIGIN = 0x00000000, LENGTH = 0x00030000
   ps7_ram_1_S_AXI_BASEADDR : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00
   ps7_ddr_0_A_AXI_MATRIX  : ORIGIN = 0x20000000, LENGTH = 0x100000
}

.matirx : {
   __matrix_start = .;
   *(.matrix)
   *(.matrix.*)
   __matrix_end = .;
} > ps7_ddr_0_A_AXI_MATRIX

_end = .;
}

注意:如果Linker Script配置不对,编译不会报错,而是直接把变量放到.data section里面。所以源码里面最好检查一下。

其他常用的Attribute

1.

aligned (alignment)
This attribute specifies a minimum alignment for the variable or structure field, measured in bytes.
例子:
int x __attribute__ ((aligned (16))) = 0;
struct foo { int x[2] __attribute__ ((aligned (8))); };
short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));

2.
packed
The packed attribute specifies that a variable or structure fieldshould have the smallest possible alignment—one byte for a variable,and one bit for a field, unless you specify a larger value with thealigned attribute.
例子:
struct foo
{
char a;
int x[2] __attribute__ ((packed));
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值