在head.s中,要保存数据段的起始位置,如下所示:
p1.l = __rambase;
p1.h = __rambase;
r0.l = __sdata;
r0.h = __sdata;
[p1] = r0;
在这里,_sdata是在vmlinux.lds.s中定义的一个值,它指向数据段的首地址,如下所示:
.data :
{
/* make sure the init_task is aligned to the
* kernel thread size so we can locate the kernel
* stack properly and quickly.
*/
__sdata = .;
. = ALIGN(THREAD_SIZE);
*(.data.init_task)
. = ALIGN(32);
*(.data.cacheline_aligned)
DATA_DATA
*(.data.*)
CONSTRUCTORS
. = ALIGN(THREAD_SIZE);
__edata = .;
}
在VDSP向导生成的LDF文件中,也需要使用数据段,不过它是把代码和数据混合放在一起的:
sdram
{
INPUT_SECTION_ALIGN(4)
INPUT_SECTIONS($OBJECTS_CORE_A(sdram_bank0) $LIBRARIES_CORE_A(sdram_bank0))
/*$VDSG<insert-input-sections-at-the-start-of-sdram-A> */
/* Text inserted between these $VDSG comments will be preserved */
/*$VDSG<insert-input-sections-at-the-start-of-sdram-A> */
INPUT_SECTIONS($OBJECTS_CORE_A(VDK_ISR_code) $LIBRARIES_CORE_A(VDK_ISR_code))
INPUT_SECTIONS($OBJECTS_CORE_A(program) $LIBRARIES_CORE_A(program))
INPUT_SECTIONS($OBJECTS_CORE_A(noncache_code) $LIBRARIES_CORE_A(noncache_code))
INPUT_SECTIONS($OBJECTS_CORE_A(sdram_data) $LIBRARIES_CORE_A(sdram_data))
INPUT_SECTIONS($OBJECTS_CORE_A(data1) $LIBRARIES_CORE_A(data1))
INPUT_SECTIONS($OBJECTS_CORE_A(voldata) $LIBRARIES_CORE_A(voldata))
INPUT_SECTIONS($OBJECTS_CORE_A(constdata) $LIBRARIES_CORE_A(constdata))
/*$VDSG<insert-input-sections-at-the-end-of-sdram-A> */
/* Text inserted between these $VDSG comments will be preserved */
/*$VDSG<insert-input-sections-at-the-end-of-sdram-A> */
} > MEM_SDRAM
因此我们需要将之拆开分成两个段:
sdram
{
INPUT_SECTION_ALIGN(4)
INPUT_SECTIONS($OBJECTS_CORE_A(sdram_bank0) $LIBRARIES_CORE_A(sdram_bank0))
/*$VDSG<insert-input-sections-at-the-start-of-sdram-A> */
/* Text inserted between these $VDSG comments will be preserved */
/*$VDSG<insert-input-sections-at-the-start-of-sdram-A> */
INPUT_SECTIONS($OBJECTS_CORE_A(VDK_ISR_code) $LIBRARIES_CORE_A(VDK_ISR_code))
INPUT_SECTIONS($OBJECTS_CORE_A(program) $LIBRARIES_CORE_A(program))
INPUT_SECTIONS($OBJECTS_CORE_A(noncache_code) $LIBRARIES_CORE_A(noncache_code))
/*$VDSG<insert-input-sections-at-the-end-of-sdram-A> */
/* Text inserted between these $VDSG comments will be preserved */
/*$VDSG<insert-input-sections-at-the-end-of-sdram-A> */
} > MEM_SDRAM
.data
{
/* make sure the init_task is aligned to the
* kernel thread size so we can locate the kernel
* stack properly and quickly.
*/
__sdata = .;
INPUT_SECTION_ALIGN(8192)
INPUT_SECTIONS($LIBRARIES_CORE_A(.data.init_task))
INPUT_SECTION_ALIGN(32)
INPUT_SECTIONS($LIBRARIES_CORE_A(.data.cacheline_aligned))
INPUT_SECTIONS($OBJECTS_CORE_A(sdram_data) $LIBRARIES_CORE_A(sdram_data))
INPUT_SECTIONS($OBJECTS_CORE_A(data1) $LIBRARIES_CORE_A(data1))
INPUT_SECTIONS($OBJECTS_CORE_A(voldata) $LIBRARIES_CORE_A(voldata))
INPUT_SECTIONS($OBJECTS_CORE_A(constdata) $LIBRARIES_CORE_A(constdata))
INPUT_SECTIONS($OBJECTS_CORE_A(.data.*))
. = (. + 8191) / 8192 * 8192;
__edata = .;
} > MEM_SDRAM
在这里直接将THREAD_SIZE替换为8192,避免在LDF中包含头文件时可能造成的问题。