[8051] [bootloader]

pfeuh
2008-04-24
2013-03-12
  • pfeuh
    pfeuh
    2008-04-24

    Hello,

    Developing a bootloader with SDCC for a Silabs C8051F411, I have a problem... Let's suppose the bootloader's size is less than 0x600 bytes and the application is located at 0x0600, I would like to write in assembler something like that:

                    org = 0x0003
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0603 ;External Interrupt 0 (/INT0)
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x060B ;Timer 0 Overflow
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0613 ;External Interrupt 1 (/INT1)
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x061B ;Timer 1 Overflow
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0623 ;UART0
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x062B ;Timer 2 Overflow
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0633 ;SPI0
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x063B ;SMB0
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0643 ;smaRTClock
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x064B ;ADC0 Window Comparator
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0653 ;ADC0 End of Conversion
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x065B ;Programmable Counter Array
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0663 ;Comparator0
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x066B ;Comparator1
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0673 ;Timer 3 Overflow
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x067B ;Voltage Regulator Dropout
                    nop
                    nop
                    nop
                    nop
                    nop
                    nop
                    AJMP    0x0683 ;Port Match

    I don't really understand the SDCC manual about _sdcc_external_startup(), __naked and so on. Do you have any idea?

    Regards,

    Pfeuh

     
    • Maarten Brock
      Maarten Brock
      2008-04-28

      If you want to write this piece of assembler then what is stopping you? Just put it in a .asm file, feed it to the assembler (asx8051) and link it with your bootloader application. Just be sure that your bootloader does not use any interrupts.

      When you link your application you use --code-loc 0x0600 to offset it to 0x0600.

       
      • pfeuh
        pfeuh
        2008-04-28

        Thank you Maarten. the problem was just the absolute location. I've found an easier way to proceed, like this:

        void Interrupt_00(void) interrupt INT_EXT0 _naked
        {
            _asm
            ljmp    0x0603;
            _endasm;
        }

        void Interrupt_01(void) interrupt INT_TIMER0 _naked
        {
            _asm
            ljmp    0x060b;
            _endasm;
        }

        And so on. Thera is now an other little problem: The targets are not directly computed, but stored in a jumps table, somewhere in bootloader code memory, like this:

        0000 02 00 86 LJMP    0086H     
        0003 02 05 07 LJMP    0507H     
        0006 FF       MOV    R7,A       
        0007 FF       MOV    R7,A       
        0008 FF       MOV    R7,A       
        0009 FF       MOV    R7,A       
        000A FF       MOV    R7,A       
        000B 02 05 0A LJMP    050AH     
        000E FF       MOV    R7,A       
        000F FF       MOV    R7,A       
        0010 FF       MOV    R7,A       
        0011 FF       MOV    R7,A       
        0012 FF       MOV    R7,A       
        0013 02 05 0D LJMP    050DH     
        0016 FF       MOV    R7,A       
        0017 FF       MOV    R7,A       
        0018 FF       MOV    R7,A       
        0019 FF       MOV    R7,A       
        001A FF       MOV    R7,A       
        001B 02 05 10 LJMP    0510H

        .../....

        0507 02 06 03 LJMP    0603H     
        050A 02 06 0B LJMP    060BH     
        050D 02 06 13 LJMP    0613H     
        0510 02 06 1B LJMP    061BH     
        0513 02 06 23 LJMP    0623H     
        0516 02 06 2B LJMP    062BH     
        0519 02 06 33 LJMP    0633H     
        051C 02 06 3B LJMP    063BH     

        a little code space is lost, and a litle time is lost at every interrupt.

        Regards,

        Pfeuh

         
        • Maarten Brock
          Maarten Brock
          2008-04-29

          To solve this you are better off with your original idea and do it in assembler. I guess you got an error message about that absolute location. It requires that the area is declared ABSolute too. Put the following above your assembly:

              .area MY_IVT (CODE,ABS)

          Good luck,
          Maarten

           
          • pfeuh
            pfeuh
            2008-04-29

            Thanks, Maarten.

            Regards,

            Pfeuh