Changeset cdfe85a7 in rtems


Ignore:
Timestamp:
Aug 11, 2009, 5:03:01 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
c8ce082
Parents:
79d490aa
Message:

2009-08-11 Josh Switnicki <josh.switnicki@…>

  • cpu.c, cpu_asm.S, rtems/score/cpu.h: Fix bug in _CPU_Context_Initialize.
Location:
cpukit/score/cpu/avr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/cpu/avr/ChangeLog

    r79d490aa rcdfe85a7  
     12009-08-11      Josh Switnicki <josh.switnicki@utoronto.ca>
     2
     3        * cpu.c, cpu_asm.S, rtems/score/cpu.h: Fix bug in
     4        _CPU_Context_Initialize.
     5
    162009-08-05      Josh Switnicki <josh.switnicki@utoronto.ca>
    27
  • cpukit/score/cpu/avr/cpu.c

    r79d490aa rcdfe85a7  
    3131void _CPU_Initialize(void)
    3232{
    33   printk( "AVR CPU Initialize\n" );
    34 
     33 
    3534  /*
    3635   *  If there is not an easy way to initialize the FP context
     
    4140
    4241  /* FP context initialization support goes here */
    43 }
    44 
    45 /*PAGE
    46  *
    47  *  _CPU_Context_Initialize
    48  *
    49  *  This kernel routine initializes the basic non-FP context area associated
    50  *  with each thread.
    51  *
    52  *  Input parameters:
    53  *    the_context  - pointer to the context area
    54  *    stack_base   - address of memory for the SPARC
    55  *    size         - size in bytes of the stack area
    56  *    new_level    - interrupt level for this context area
    57  *    entry_point  - the starting execution point for this this context
    58  *    is_fp        - TRUE if this context is associated with an FP thread
    59  *
    60  *  Output parameters: NONE
    61  */
    62 
    63 void _CPU_Context_Initialize(
    64   Context_Control  *the_context,
    65   uint32_t         *stack_base,
    66   uint32_t          size,
    67   uint32_t          new_level,
    68   void             *entry_point,
    69   bool              is_fp
    70 )
    71 {
    72   uint16_t stack;
    73   uint16_t start;
    74   uint8_t  *tmp_sp;
    75   uint8_t   start_low;
    76   uint8_t   start_high;
    77 
    78   /* calc stack high end */
    79   stack = (uint16_t) (stack_base) + (uint16_t) (size);
    80   /* calc stack pointer initial value */
    81   the_context->stack_pointer = (stack - 18);
    82   /* put the entry point on the stack */
    83   start = (uint16_t) entry_point;
    84   start_low = start & 0xff;
    85   start_high = start >> 8;
    86   tmp_sp = (uint8_t *) (stack+1);
    87   tmp_sp[0] = start_high;
    88   tmp_sp[1] = start_low;
    89 
    90   if (new_level) the_context->status = 0x00; //interrupts are enabled
    91   else           the_context->status = 0x80; //interrupts are disabled
    92 
    93   /*
    94    * JOEL: Why if I comment out these three lines does ticker not run?
    95    */
    96 #if 1
    97   printk( "tmp_sp=0x%04x ", ((uint16_t)tmp_sp) );
    98   printk("the_context = 0x%x\n", the_context);
    99   printk("entry = 0x%x\n", entry_point);
    100 #endif
    101 #if 0
    102   printk("sp = 0x%x\n\n",stack);
    103 
    104  { int i; uint8_t *p;
    105    p = (uint8_t *)(stack - 18);
    106    for( i=0 ; i<=20 ; i+=8 ) {
    107      printk( "0x%04x ", ((uint16_t)&p[i]) );
    108      printk(
    109       "0x%02x 0x%02x 0x%02x 0x%02x   ",
    110       p[i + 0], p[i + 1], p[i + 2], p[i + 3]
    111      );
    112      printk(
    113       "0x%02x 0x%02x 0x%02x 0x%02x\n",
    114       p[i + 4], p[i + 5], p[i + 6], p[i + 7]
    115      );
    116    }
    117  }
    118 #endif
    11942}
    12043
     
    13356   *  This routine returns the current interrupt level.
    13457   */
     58  if((SREG & 0x80))return 1;
     59  else  return 0;
    13560
    136   return 0;
    13761}
    13862
  • cpukit/score/cpu/avr/cpu_asm.S

    r79d490aa rcdfe85a7  
    209209        PUBLIC(_CPU_Context_switch)
    210210SYM(_CPU_Context_switch):
    211         mov     r26, r24        /* r26,r27 is X or current context */
     211        mov     r26, r24        /*r26,r27 is X*/
    212212        mov     r27, r25
    213         mov     r24, r22        /* r24,r25 is heir context */
     213        mov     r24, r22
    214214        mov     r25, r23
    215215        /*save registers*/
     216#if 1
     217/*if this section is removed there is a problem.*/
     218/*debug section start*/
     219        pop     r22
     220        pop     r23
     221        push    r22
     222        push    r23
     223/*debug section end*/
     224#endif
     225
    216226        push    r2
    217227        push    r3
     
    230240        push    r16
    231241        push    r17
     242
    232243        push    r28
    233244        push    r29
     245
    234246        /*load sreg*/
    235         lds     r23,0x5F  /*load sreg*/
     247        lds     r23,0x5f  /*load sreg*/
    236248        /*disable interrupts*/
    237249        cli
    238250        /*load stack pointer*/
    239         lds     r22,0x5D /*spl*/
    240         lds     r21,0x5E /*sph*/
    241         /*save sp to context struct*/
     251        lds     r22,0x5d /*spl*/
     252        lds     r21,0x5e /*sph*/
     253        /*save sreg and sp to context struct*/
     254
    242255        /*save low then high byte --- verify this delete when verified*/
    243256        st      X+, r22
    244257        st      X+, r21
    245         /*save sreg and sp to context struct*/
    246258        st      X, r23
    247 
    248259
    249260        PUBLIC(_CPU_Context_restore)
     
    252263        mov     r26,r24         /* R26/27 are X */
    253264        mov     r27,r25
     265
    254266        /*restore stack pointer*/
    255267        ld      r25, X+
    256268        ld      r24, X+
    257         sts     0x5E, r24 /*sph*/
    258         sts     0x5D, r25 /*spl*/
     269        sts     0x5E,r24 /*sph*/
     270        sts     0x5D ,r25 /*spl*/
    259271        /*restore registers from stack*/
     272
     273
    260274        pop     r29
    261275        pop     r28
     276
     277
    262278        pop     r17
    263279        pop     r16
     
    276292        pop     r3
    277293        pop     r2
    278         /*restore status register*/
    279         ld      r23, X
    280         sts     0x5f,r23 /*sreg*/       
     294
     295        /*restore sreg*/
     296        ld      r25, X
     297        sts     0x5f,r25 /*sreg*/
     298        pop     r30
     299        pop     r31
     300        IJMP
    281301        ret
    282302
    283303
    284304
    285 /*
    286  *  _CPU_Context_restore
    287  *
    288  *  This routine is generally used only to restart self in an
    289  *  efficient manner.  It may simply be a label in _CPU_Context_switch.
    290  *
    291  *  NOTE: May be unnecessary to reload some registers.
    292  *
    293  *  NO_CPU Specific Information:
    294  *
    295  *  XXX document implementation including references if appropriate
    296  
    297 
    298 void _CPU_Context_restore(
    299   Context_Control *new_context
    300 )
    301 {
    302   printk( "AVR _CPU_Context_restore\n" );
    303 }
    304 */
    305 /*
    306         PUBLIC(_CPU_Context_restore)
    307 
    308 SYM(_CPU_Context_restore):
    309         //call printk("AVR _CPU_Context_restore\n")
    310         ret
    311 
    312 */
     305/*PAGE
     306 *
     307 *  _CPU_Context_Initialize
     308 *
     309 *  This kernel routine initializes the basic non-FP context area associated
     310 *  with each thread.
     311 *
     312 *  Input parameters:
     313 *    the_context  - pointer to the context area
     314 *    stack_base   - address of memory for the SPARC
     315 *    size         - size in bytes of the stack area
     316 *    new_level    - interrupt level for this context area
     317 *    entry_point  - the starting execution point for this this context
     318 *    is_fp        - TRUE if this context is associated with an FP thread
     319 *
     320 *      the_context is in r25,r24
     321 *      entry point is in r13,r12
     322 *      stack base is in r23, r22
     323 *      size is in r21, r20, r19,r18
     324 *      newleve is in r14,r15, r16, 17
     325 *
     326 *
     327 *  Output parameters: NONE
     328 */
     329
     330        PUBLIC(_CPU_Context_Initialize)
     331SYM(_CPU_Context_Initialize):
     332        //save caller saved regs
     333        PUSH    R10
     334        PUSH    R11
     335        PUSH    R12
     336        PUSH    R13
     337        PUSH    R14
     338        PUSH    R15
     339        PUSH    R16
     340        PUSH    R17
     341        PUSH    R28
     342        PUSH    R29
     343        //calculate new stack pointer
     344        ADD     R22, R18
     345        ADC     R23, R19
     346        MOV     R26, R22
     347        MOV     R27, R23
     348        //Initialize stack with entry point
     349        ST      -X, R13
     350        ST      -X, R12
     351        //store new stack pointer in context control
     352        SBIW    R26, 0X13       /*subtract 33 to account for registers*/
     353        MOV     R28, R24
     354        MOV     R29, R25
     355        STD     Y+1, R27        //save stack pointer high to context control
     356        ST      Y, R26          //save stack pointer low to context control
     357        //set interrupt level in new context
     358        LDI     R18, 0          //set sreg in new context to zero
     359        STD     Y+2, R18        //interrupts not enabled               
     360        MOV     R18, R14
     361        CPI     R18, 0
     362        BRNE    NEW_LEVEL_ZERO
     363        LDI     R18, 0X80       //set sreg in new context to 0x80
     364        STD     Y+2, R18        //interupts enabled
     365NEW_LEVEL_ZERO:
     366        //restore caller saved regs
     367        POP     R29
     368        POP     R28
     369        POP     R17
     370        POP     R16
     371        POP     R15
     372        POP     R14
     373        POP     R13
     374        POP     R12
     375        POP     R11
     376        POP     R10
     377        RET
     378       
     379
    313380
    314381/*  void __ISR_Handler()
  • cpukit/score/cpu/avr/rtems/score/cpu.h

    r79d490aa rcdfe85a7  
    763763
    764764#define _CPU_Context_Restart_self( _the_context ) \
    765    _CPU_Context_restore( (_the_context) );
     765   _CPU_Context_restore( _the_context );
    766766
    767767/*
Note: See TracChangeset for help on using the changeset viewer.