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

User Stack Placement

I am considering placing the user stack into internal ram. It defaults into near which is assigned to the first 16k external ram. I am a bit confused about the asm in the startup file. The section Ex.1, see below, obviously places the user stack into near (NDATA) so i assume changing this to either IDATA or SDATA will do the trick. But after this, the section Ex.2, see below, refers the user stack to NDATA. So should this change too? If i change it, i get an error A77: Missing DPP info. Can anyone help tell me what is going on and if it is a good idea to move the user stack to internal ram in the first place.

Section Ex.1
?C_USERSTACK    SECTION DATA PUBLIC 'NDATA'
?C_USRSTKBOT:
                DS      USTSZ           ; Size of User Stack
?C_USERSTKTOP:
?C_USERSTACK    ENDS

Section Ex.2
$IF NOT TINY
IF (UST1SZ > 0) AND (UST2SZ > 0)        ; Define User Stack 1 area
NDATA           DGROUP  ?C_USERSTACK, ?C_USERSTACK1, ?C_USERSTACK2
ENDIF

Parents
  • I was a bit surprised that this actually works because ?C_USERSTKTOP is still listed belonging to the NDATA group.

    Hi, where are you refering to when you say it still belongs to NDATA? I thought if we changed the references of NDATA to SDATA (or IDATA) this placed the stack in internal ram?

    ?C_USERSTACK    SECTION DATA PUBLIC 'NDATA'
    
    IF (UST1SZ > 0) AND (UST2SZ > 0)        ; Define User Stack area
    NDATA           DGROUP  ?C_USERSTACK, ?C_USERSTACK1, ?C_USERSTACK2
    ENDIF
    

    I have used the HOLD directive in modules to do as you suggested. Thanks.

    I am a bit confused about the DPP's now, i understand what they do but am struggling to see their useage in my application, are they only relevent in memory models that use near & far pointers? I am using 'HLarge' and i cannot see any difference is speed accessing near data than huge data. I created a simple loop which accessed data via a pointer, first in near then in huge but there was no difference in speed. As i understand the point of DPP's was to create fast access to near data. DPP2 does hold the value for the base of near data but i cannot see how its being used. DPP2=0x0020, Ext Ram=0x80000.

    Do i need to specify the DPPUSE directive or something? Or am i just being stupid! How do i check they are being used and why is access to near data no faster than huge? If there is any easy advise you can give. Thanks.

Reply
  • I was a bit surprised that this actually works because ?C_USERSTKTOP is still listed belonging to the NDATA group.

    Hi, where are you refering to when you say it still belongs to NDATA? I thought if we changed the references of NDATA to SDATA (or IDATA) this placed the stack in internal ram?

    ?C_USERSTACK    SECTION DATA PUBLIC 'NDATA'
    
    IF (UST1SZ > 0) AND (UST2SZ > 0)        ; Define User Stack area
    NDATA           DGROUP  ?C_USERSTACK, ?C_USERSTACK1, ?C_USERSTACK2
    ENDIF
    

    I have used the HOLD directive in modules to do as you suggested. Thanks.

    I am a bit confused about the DPP's now, i understand what they do but am struggling to see their useage in my application, are they only relevent in memory models that use near & far pointers? I am using 'HLarge' and i cannot see any difference is speed accessing near data than huge data. I created a simple loop which accessed data via a pointer, first in near then in huge but there was no difference in speed. As i understand the point of DPP's was to create fast access to near data. DPP2 does hold the value for the base of near data but i cannot see how its being used. DPP2=0x0020, Ext Ram=0x80000.

    Do i need to specify the DPPUSE directive or something? Or am i just being stupid! How do i check they are being used and why is access to near data no faster than huge? If there is any easy advise you can give. Thanks.

Children
  • Hi, where are you refering to when you say it still belongs to NDATA?

    I was referring to the original startup file modified as suggested by Keil to place the stack to internal RAM. Then these lines remain saying that user stack is in NDATA:

    $IF NOT TINY
    IF (UST1SZ > 0) AND (UST2SZ > 0)        ; Define User Stack 1 area
    NDATA           DGROUP  ?C_USERSTACK, ?C_USERSTACK1, ?C_USERSTACK2
    .
    .
    IF (UST1SZ = 0) AND (UST2SZ = 0)
    NDATA           DGROUP  ?C_USERSTACK
    ENDIF
    $ENDIF
    

    The usage of the DPP registers is described in the compiler documentation. The default usage is:
    DPP0 Not used for C167.
    DPP1 Used for accessing near constants (NCONST)
    DPP2 Used for accessing near data (NDATA)
    DPP3 Used for accessing SYSTEM area, 0xC000-0xFFFF.

    You can change the usage with the DPPUSE directive.

    DPP addressing is explained in the XC167 User's Manual. The DPP registers are used in indirect and direct long (16 bit) modes. The two most significant bits of the 16 bit address (GPR or memory address) select the DPP register (and thus the page), and bits 13..0 are the offset into the page.

    For example:
    DPP2 = 0x0020
    R0 = 0x8040

    The two most significant bits of R0 are 10, which selects DPP2. The 24 bit address referenced then is:
    (DPP2 << 14) + (R0 & 0x3FF) = 0x80040

    The reason you don't see any difference in the speed of accessing near/huge data is that you access it with a pointer, which in hlarge model is a 24 bit pointer, and the DPP adressing mechanism is not used. If you know that a pointer always points to near data, you may want to explicitly tell the compiler so (e.g. char * near p;, if memory serves me correct).

    Sauli

  • Many thanks for all your help Sauli, i think i have it about sorted now. I probably shouldnt post thankyou's, but there you go.

    P.s. I thought it was as you described but this seems to be the case:-

    char * near ptr_in_near; // puts the pointer in near whereas,
    char near *near_ptr; // make it a near pointer

    Cheers.