Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
70
Добавлен:
14.04.2015
Размер:
2.03 Mб
Скачать

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

289

 

 

Tips and Tricks for Program Locating

The Lx51 linker/locator supports several techniques that are required in for

9

special tasks, for example in-system Flash programming or systems that use a

RAM section for constants. The following section provides examples that show the usage of the Lx51 linker/locater in such situations.

Locate Segments with Wildcards

The Lx51 linker/locater allows in the segment controls wildcards for specifying the segment name. For example you may use such segment name specifications to locate all segments within one module into one 2KB block. In this way you can use the ACALL and AJMP instructions for function calls within this module.

BL51 myfile.obj CODE (?PR?*?myfile (0x1000))

LX51 myfile.obj SEGMENTS (?PR?*?myfile (C:0x1000))

 

290

Chapter 9. Linker/Locator

 

 

 

Special ROM Handling (LX51 & L251 only)

9

The LX51 and L251 linker/locater provide the memory class SROM that is used

to handle segments or memory classes that are to be stored in ROM, but copied

 

for execution into RAM areas. This is useful for:

 

 

In-system Flash programming when the Flash ROM contains also the flash

 

 

programming code. With standard Flash devices it is impossible to fetch

 

 

program code from the while other parts of the device are erased or

 

 

programmed. The Keil Application Note 139: “In-system Flash

 

 

Programming with 8051 and 251” that is available on www.keil.com or the

 

 

Keil development tools CD-ROM contains a program example.

 

 

For using the C251 TINY or XTINY memory model it is required to provide

 

 

a NCONST memory class in the lowest 64KB memory region. However, if

only RAM is mapped into this memory region, you can specify a different storage address for the NCONST memory class and copy the content at the program start into RAM. This allows you to use the efficient TINY or XTINY memory model while the system hardware just provides RAM in the lowest 64KB memory segment. Refer to “Use RAM for the 251 Memory Class NCONST” on page 292 for a program example.

Refer to Lx51 linker/locater controls “SEGMENTS” on page 346 and “CLASSES” on page 336 for syntax on defining segments and memory classes that have a different storage and execution address.

_NCONST_L_ _NCONST_S_ _NCONST_E_ _NCONST_T_
_PR_FUNC1_L_ _PR_FUNC1_S_ _PR_FUNC1_E_ _PR_FUNC1_T_

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

291

 

 

Segment and Class Information (LX51 & L251 only)

The Lx51 linker/locater creates special symbols that can be used to obtain

9

address and length information for segments or classes used in an application.

The information is passed via external variable declarations. The Lx51

 

linker/locater uses symbols with the notation segmentname_p_ or

 

_classname_p_. Question mark (?) characters in the segment name generated by

 

the Cx51 compiler are replaced with underscore (_) characters. The postfix _p_

 

specifies the information that should be obtained and is explained in the

 

following table:

 

 

 

 

 

 

 

 

 

Postfix

 

Description

 

 

 

 

_l_

 

is the length in bytes of the segment or memory class. For a memory class this

 

 

 

 

 

 

number includes also any gaps that are required to allocate all segments that belong to

 

 

 

 

 

 

this memory class.

 

 

 

 

_s_

 

is the start address of the segment or memory class. For a memory class this number

 

 

 

 

 

 

refers to the first segment that belongs to this memory class.

 

 

 

 

_e_

 

is the end address of the segment or memory class. For a memory class this number

 

 

 

 

 

 

refers to the last segment that belongs to this memory class.

 

 

 

 

_t_

 

is the target or execution address of the segment or memory class. For a memory

 

 

 

 

 

 

 

 

 

 

 

class this number refers to the first segment that belongs to this memory class. This

 

 

 

 

 

 

information is only available for segments or memory classes which have assigned a

 

 

 

 

 

 

different storage and execution address.

 

 

 

Examples:

If ?PR?FUNC1 is the segment name:

is the length in bytes of the segment ?PR?FUNC1. is the start address of the segment ?PR?FUNC1. is the end address of the segment ?PR?FUNC1.

is the target or execution address of the segment ?PR?FUNC1.

If NCONST is the memory class name:

is the length in bytes of the memory class NCONST. is the start address of the memory class NCONST. is the end address of the memory class NCONST.

is the target or execution address of the memory class NCONST.

292 Chapter 9. Linker/Locator

 

 

You may access this information in Cx51 applications as shown in the following

 

 

program example:

 

9

 

 

 

 

extern char _PR_FUNC1_L_;

 

 

unsigned int get_length (void) {

 

 

return ((unsigned int) &_PR_FUNC1_L_); // length of segment ?PR?FUNC1

 

 

 

}

 

 

 

The file SROM.H contains macro definitions for accessing segment and class

 

 

information. Refer to the Keil Application Note 139: “In-system Flash

 

 

Programming with 8051 and 251” for more information.

 

 

Use RAM for the 251 Memory Class NCONST

 

 

The C251 compiler memory model TINY or XTINY requires a NCONST

 

 

memory class in the lowest 64KB memory region. If your hardware provides

 

 

only RAM in this memory area, you may use the SROM memory class to store

 

 

the constants somewhere in the 16MB memory space and you may copy the

 

 

content of the NCONST memory class into a RAM in the lowest 64KB memory.

 

 

This is shown in the following program example. Refer to the “CLASSES”

 

 

control on page 336 for more information.

 

 

#include <string.h>

 

 

extern char huge _NCONST_S_;

 

 

extern char huge _NCONST_T_;

 

 

extern char near

_NCONST_L_;

 

 

const char text [] = "This text is accessed in the NCONST memory class";

 

 

void main (void)

{

 

 

fmemcpy (&_NCONST_T_, &_NCONST_S_, (unsigned int)&_NCONST_L_);

:

}

The C251 compiler and L251 linker/locater is invoke as follows:

C251 SAMPLE.C XTINY DEBUG

L251 SAMPLE.C CLASSES (NCONST (0x2000-0x4000)[]), SROM (0xFE0000-0xFEFFFF)

Соседние файлы в папке HLP