This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem regarding printf

My program is as follows:

void main(void)
{
	char far *ptr;

	ptr = 0x200000;
	printf("ptr = %p\r\n", ptr);
	while(1);
}
I simulate it with Keil debugger, the result is as follows:
#1 After executing "ptr = 0x210000;",
in Watch & Call Stack Window-Locals subwindow,
I see the value of ptr is ????????;

#2 Step over "printf"
Popup Disassembly Window, PC = C:0x1F0130(the entry point of printf)
Output Window "error 65: access violation at X:0x400003 : no 'write' permission"

#3 Click "Step Over" several times
Popup Disassembly Window, PC = C:0x000000
Output Window "error 65: access violation at X:0x400006 : no 'write' permission"
Output Window "error 65: access violation at X:0x400004 : no 'read' permission"

#4 I have my program run in application board, result is normal!

Other information:
CPU = DS80C400
FREQ = 11.0592MHz
Contiguous Mode: 16MB
Off-chip code memory: 0x1F0000(start), 0x10000(length)
Off-chip xdata memory: 0x200000(start), 0x10000(length)
Enable "far memory type support"
Enable LX51 & AX51
Startup file: startup400.a51(from DALLAS SEMI)

Parents
  • ptr = 0x200000
    #1 After executing "ptr = 0x210000;"
    Off-chip xdata memory: 0x200000(start), 0x10000(length)


    The 8051 does not have a linear address space, and the values of a far pointer are unfortunately not simply the offset into xdata. The far pointer format is an extension of the "generic" 3-byte pointer format, in which one of the bytes is a tag byte identifying the memory space. For far memory, that tag byte identifies a 64Kbyte segment of far xdata memory. For what I assume are historical reasons, though, xdata starts with a tag value of 1, not 0. That is, the pointer values are "off by 0x10000".

    At any rate, you should use the
    FVAR, FARRAY, FCVAR, FCARRAY macros in absacc.h to construct a pointer from an offset rather than using integer values. The macros contain the proper offsets to make the tag byte come out with the correct value.

    Also, check the Debug / Memory Map menu option to be sure you have the memory ranges and access permissions set up appropriately.

Reply
  • ptr = 0x200000
    #1 After executing "ptr = 0x210000;"
    Off-chip xdata memory: 0x200000(start), 0x10000(length)


    The 8051 does not have a linear address space, and the values of a far pointer are unfortunately not simply the offset into xdata. The far pointer format is an extension of the "generic" 3-byte pointer format, in which one of the bytes is a tag byte identifying the memory space. For far memory, that tag byte identifies a 64Kbyte segment of far xdata memory. For what I assume are historical reasons, though, xdata starts with a tag value of 1, not 0. That is, the pointer values are "off by 0x10000".

    At any rate, you should use the
    FVAR, FARRAY, FCVAR, FCARRAY macros in absacc.h to construct a pointer from an offset rather than using integer values. The macros contain the proper offsets to make the tag byte come out with the correct value.

    Also, check the Debug / Memory Map menu option to be sure you have the memory ranges and access permissions set up appropriately.

Children