You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/11/22 08:28:04 UTC

[incubator-nuttx] 01/02: arch: rename arch special function name

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit a8fa51e6bf51791272a0a65a69e029aa9eb8d1ba
Author: zhangyuan21 <zh...@xiaomi.com>
AuthorDate: Thu Nov 17 18:17:40 2022 +0800

    arch: rename arch special function name
---
 arch/arm/src/tlsr82/tc32/tc32_saveusercontext.S    |   4 +-
 arch/arm64/include/syscall.h                       |   2 +-
 arch/avr/src/at32uc3/Make.defs                     |  20 +-
 arch/avr/src/at32uc3/at32uc3_clkinit.c             |   2 +-
 arch/avr/src/at32uc3/at32uc3_gpio.c                |   2 +-
 arch/avr/src/at32uc3/at32uc3_gpioirq.c             |   2 +-
 arch/avr/src/at32uc3/at32uc3_irq.c                 |   2 +-
 arch/avr/src/at32uc3/at32uc3_lowconsole.c          |   8 +-
 arch/avr/src/at32uc3/at32uc3_lowinit.c             |   8 +-
 arch/avr/src/at32uc3/at32uc3_serial.c              |  22 +-
 arch/avr/src/at32uc3/at32uc3_timerisr.c            |   2 +-
 arch/avr/src/at90usb/Make.defs                     |  24 +-
 arch/avr/src/at90usb/at90usb_exceptions.S          |  12 +-
 arch/avr/src/at90usb/at90usb_head.S                |   4 +-
 arch/avr/src/at90usb/at90usb_lowconsole.c          |   6 +-
 arch/avr/src/at90usb/at90usb_lowinit.c             |   8 +-
 arch/avr/src/at90usb/at90usb_serial.c              |  22 +-
 arch/avr/src/at90usb/at90usb_timerisr.c            |   2 +-
 arch/avr/src/at90usb/at90usb_usbdev.c              |  12 +-
 arch/avr/src/atmega/Make.defs                      |  24 +-
 arch/avr/src/atmega/atmega_exceptions.S            |  12 +-
 arch/avr/src/atmega/atmega_head.S                  |   4 +-
 arch/avr/src/atmega/atmega_lowconsole.c            |   6 +-
 arch/avr/src/atmega/atmega_lowinit.c               |   8 +-
 arch/avr/src/atmega/atmega_serial.c                |  22 +-
 arch/avr/src/atmega/atmega_timerisr.c              |   2 +-
 arch/avr/src/avr/avr.h                             |  20 +-
 arch/avr/src/avr/avr_blocktask.c                   | 109 +++
 arch/avr/src/avr/avr_checkstack.c                  | 179 +++++
 arch/avr/src/avr/avr_copystate.c                   |  70 ++
 arch/avr/src/avr/avr_createstack.c                 | 191 ++++++
 arch/avr/src/avr/avr_doirq.c                       | 101 +++
 arch/avr/src/avr/avr_dumpstate.c                   | 220 ++++++
 arch/avr/src/avr/avr_initialstate.c                | 115 ++++
 arch/avr/src/avr/avr_irq.c                         |  64 ++
 arch/avr/src/avr/avr_releasepending.c              | 114 ++++
 arch/avr/src/avr/avr_romgetc.c                     |  91 +++
 arch/avr/src/avr/avr_schedulesigaction.c           | 194 ++++++
 arch/avr/src/avr/avr_sigdeliver.c                  | 127 ++++
 arch/avr/src/avr/avr_spi.c                         | 488 +++++++++++++
 arch/avr/src/avr/avr_stackframe.c                  |  94 +++
 arch/avr/src/avr/avr_switchcontext.S               | 123 ++++
 arch/avr/src/avr/avr_unblocktask.c                 | 100 +++
 arch/avr/src/avr/avr_usestack.c                    | 113 +++
 arch/avr/src/avr/excptmacros.h                     |   2 +-
 arch/avr/src/avr/up_blocktask.c                    | 109 ---
 arch/avr/src/avr/up_checkstack.c                   | 179 -----
 arch/avr/src/avr/up_copystate.c                    |  70 --
 arch/avr/src/avr/up_createstack.c                  | 191 ------
 arch/avr/src/avr/up_doirq.c                        | 101 ---
 arch/avr/src/avr/up_dumpstate.c                    | 220 ------
 arch/avr/src/avr/up_initialstate.c                 | 115 ----
 arch/avr/src/avr/up_irq.c                          |  64 --
 arch/avr/src/avr/up_releasepending.c               | 114 ----
 arch/avr/src/avr/up_romgetc.c                      |  91 ---
 arch/avr/src/avr/up_schedulesigaction.c            | 194 ------
 arch/avr/src/avr/up_sigdeliver.c                   | 127 ----
 arch/avr/src/avr/up_spi.c                          | 488 -------------
 arch/avr/src/avr/up_stackframe.c                   |  94 ---
 arch/avr/src/avr/up_switchcontext.S                | 123 ----
 arch/avr/src/avr/up_unblocktask.c                  | 100 ---
 arch/avr/src/avr/up_usestack.c                     | 113 ---
 arch/avr/src/avr32/avr32.h                         |  20 +-
 arch/avr/src/avr32/avr_blocktask.c                 | 124 ++++
 arch/avr/src/avr32/avr_copystate.c                 |  71 ++
 arch/avr/src/avr32/avr_createstack.c               | 212 ++++++
 arch/avr/src/avr32/avr_doirq.c                     | 121 ++++
 arch/avr/src/avr32/avr_dumpstate.c                 | 191 ++++++
 arch/avr/src/avr32/avr_exceptions.S                | 359 ++++++++++
 arch/avr/src/avr32/avr_fullcontextrestore.S        | 143 ++++
 arch/avr/src/avr32/avr_initialstate.c              | 127 ++++
 arch/avr/src/avr32/avr_nommuhead.S                 | 140 ++++
 arch/avr/src/avr32/avr_releasepending.c            | 130 ++++
 arch/avr/src/avr32/avr_schedulesigaction.c         | 169 +++++
 arch/avr/src/avr32/avr_sigdeliver.c                | 127 ++++
 arch/avr/src/avr32/avr_stackframe.c                |  98 +++
 arch/avr/src/avr32/avr_switchcontext.S             | 107 +++
 arch/avr/src/avr32/avr_syscall6.S                  |  70 ++
 arch/avr/src/avr32/avr_unblocktask.c               | 111 +++
 arch/avr/src/avr32/avr_usestack.c                  | 126 ++++
 arch/avr/src/avr32/up_blocktask.c                  | 124 ----
 arch/avr/src/avr32/up_copystate.c                  |  71 --
 arch/avr/src/avr32/up_createstack.c                | 212 ------
 arch/avr/src/avr32/up_doirq.c                      | 121 ----
 arch/avr/src/avr32/up_dumpstate.c                  | 191 ------
 arch/avr/src/avr32/up_exceptions.S                 | 359 ----------
 arch/avr/src/avr32/up_fullcontextrestore.S         | 143 ----
 arch/avr/src/avr32/up_initialstate.c               | 127 ----
 arch/avr/src/avr32/up_nommuhead.S                  | 140 ----
 arch/avr/src/avr32/up_releasepending.c             | 130 ----
 arch/avr/src/avr32/up_schedulesigaction.c          | 169 -----
 arch/avr/src/avr32/up_sigdeliver.c                 | 127 ----
 arch/avr/src/avr32/up_stackframe.c                 |  98 ---
 arch/avr/src/avr32/up_switchcontext.S              | 107 ---
 arch/avr/src/avr32/up_syscall6.S                   |  70 --
 arch/avr/src/avr32/up_unblocktask.c                | 111 ---
 arch/avr/src/avr32/up_usestack.c                   | 126 ----
 arch/avr/src/common/avr_allocateheap.c             |  72 ++
 arch/avr/src/common/avr_assert.c                   | 163 +++++
 arch/avr/src/common/avr_exit.c                     | 149 ++++
 arch/avr/src/common/avr_idle.c                     |  71 ++
 arch/avr/src/common/avr_initialize.c               | 175 +++++
 arch/avr/src/common/avr_internal.h                 | 170 +++++
 arch/avr/src/common/avr_lowputs.c                  |  59 ++
 arch/avr/src/common/avr_mdelay.c                   |  75 ++
 arch/avr/src/common/avr_modifyreg16.c              |  70 ++
 arch/avr/src/common/avr_modifyreg32.c              |  70 ++
 arch/avr/src/common/avr_modifyreg8.c               |  70 ++
 arch/avr/src/common/avr_nputs.c                    |  58 ++
 arch/avr/src/common/avr_releasestack.c             | 106 +++
 arch/avr/src/common/avr_udelay.c                   | 118 ++++
 arch/avr/src/common/up_allocateheap.c              |  72 --
 arch/avr/src/common/up_assert.c                    | 163 -----
 arch/avr/src/common/up_exit.c                      | 149 ----
 arch/avr/src/common/up_idle.c                      |  71 --
 arch/avr/src/common/up_initialize.c                | 175 -----
 arch/avr/src/common/up_internal.h                  | 170 -----
 arch/avr/src/common/up_lowputs.c                   |  59 --
 arch/avr/src/common/up_mdelay.c                    |  75 --
 arch/avr/src/common/up_modifyreg16.c               |  70 --
 arch/avr/src/common/up_modifyreg32.c               |  70 --
 arch/avr/src/common/up_modifyreg8.c                |  70 --
 arch/avr/src/common/up_nputs.c                     |  58 --
 arch/avr/src/common/up_releasestack.c              | 106 ---
 arch/avr/src/common/up_udelay.c                    | 118 ----
 arch/ceva/include/syscall.h                        |   4 +-
 arch/ceva/src/common/ceva_assert.c                 | 372 ++++++++++
 arch/ceva/src/common/ceva_blocktask.c              | 102 +++
 arch/ceva/src/common/ceva_board.c                  | 180 +++++
 arch/ceva/src/common/ceva_checkstack.c             | 172 +++++
 arch/ceva/src/common/ceva_createstack.c            | 265 ++++++++
 arch/ceva/src/common/ceva_doirq.c                  | 106 +++
 arch/ceva/src/common/ceva_exit.c                   |  84 +++
 arch/ceva/src/common/ceva_fullcontextrestore.c     |  52 ++
 arch/ceva/src/common/ceva_heap.c                   | 272 ++++++++
 arch/ceva/src/common/ceva_idle.c                   | 170 +++++
 arch/ceva/src/common/ceva_initialize.c             | 119 ++++
 arch/ceva/src/common/ceva_internal.h               | 314 +++++++++
 arch/ceva/src/common/ceva_modifyreg16.c            |  53 ++
 arch/ceva/src/common/ceva_modifyreg32.c            |  53 ++
 arch/ceva/src/common/ceva_modifyreg8.c             |  53 ++
 arch/ceva/src/common/ceva_nputs.c                  |  46 ++
 arch/ceva/src/common/ceva_pthread_start.c          |  70 ++
 arch/ceva/src/common/ceva_releasepending.c         | 114 ++++
 arch/ceva/src/common/ceva_releasestack.c           | 110 +++
 arch/ceva/src/common/ceva_saveusercontext.c        |  68 ++
 arch/ceva/src/common/ceva_schedulesigaction.c      | 215 ++++++
 arch/ceva/src/common/ceva_sigdeliver.c             |  96 +++
 arch/ceva/src/common/ceva_signal_dispatch.c        |  75 ++
 arch/ceva/src/common/ceva_stackframe.c             |  96 +++
 arch/ceva/src/common/ceva_start.c                  | 308 +++++++++
 arch/ceva/src/common/ceva_svcall.c                 | 415 +++++++++++
 arch/ceva/src/common/ceva_switchcontext.c          |  52 ++
 arch/ceva/src/common/ceva_task_start.c             |  70 ++
 arch/ceva/src/common/ceva_unblocktask.c            |  96 +++
 arch/ceva/src/common/ceva_userspace.c              | 231 +++++++
 arch/ceva/src/common/ceva_usestack.c               | 122 ++++
 arch/ceva/src/common/ceva_vfork.c                  | 208 ++++++
 arch/ceva/src/common/up_assert.c                   | 372 ----------
 arch/ceva/src/common/up_blocktask.c                | 102 ---
 arch/ceva/src/common/up_board.c                    | 180 -----
 arch/ceva/src/common/up_checkstack.c               | 172 -----
 arch/ceva/src/common/up_createstack.c              | 265 --------
 arch/ceva/src/common/up_doirq.c                    | 106 ---
 arch/ceva/src/common/up_exit.c                     |  84 ---
 arch/ceva/src/common/up_fullcontextrestore.c       |  52 --
 arch/ceva/src/common/up_heap.c                     | 272 --------
 arch/ceva/src/common/up_idle.c                     | 170 -----
 arch/ceva/src/common/up_initialize.c               | 119 ----
 arch/ceva/src/common/up_internal.h                 | 314 ---------
 arch/ceva/src/common/up_modifyreg16.c              |  53 --
 arch/ceva/src/common/up_modifyreg32.c              |  53 --
 arch/ceva/src/common/up_modifyreg8.c               |  53 --
 arch/ceva/src/common/up_nputs.c                    |  46 --
 arch/ceva/src/common/up_pthread_start.c            |  70 --
 arch/ceva/src/common/up_releasepending.c           | 114 ----
 arch/ceva/src/common/up_releasestack.c             | 110 ---
 arch/ceva/src/common/up_saveusercontext.c          |  68 --
 arch/ceva/src/common/up_schedulesigaction.c        | 215 ------
 arch/ceva/src/common/up_sigdeliver.c               |  96 ---
 arch/ceva/src/common/up_signal_dispatch.c          |  75 --
 arch/ceva/src/common/up_stackframe.c               |  96 ---
 arch/ceva/src/common/up_start.c                    | 308 ---------
 arch/ceva/src/common/up_svcall.c                   | 414 -----------
 arch/ceva/src/common/up_switchcontext.c            |  52 --
 arch/ceva/src/common/up_task_start.c               |  70 --
 arch/ceva/src/common/up_unblocktask.c              |  96 ---
 arch/ceva/src/common/up_userspace.c                | 231 -------
 arch/ceva/src/common/up_usestack.c                 | 122 ----
 arch/ceva/src/common/up_vfork.c                    | 208 ------
 arch/ceva/src/xc5/up_hardfault.c                   |  93 ---
 arch/ceva/src/xc5/up_head.S                        | 302 --------
 arch/ceva/src/xc5/up_icache.c                      | 294 --------
 arch/ceva/src/xc5/up_initialstate.c                | 107 ---
 arch/ceva/src/xc5/up_intc.c                        | 201 ------
 arch/ceva/src/xc5/up_mpu.c                         | 130 ----
 arch/ceva/src/xc5/up_psu.c                         |  73 --
 arch/ceva/src/xc5/up_relocate.c                    |  87 ---
 arch/ceva/src/xc5/up_signal_handler.S              |  99 ---
 arch/ceva/src/xc5/up_svcall_handler.S              | 110 ---
 arch/ceva/src/xc5/xc5_hardfault.c                  |  93 +++
 arch/ceva/src/xc5/xc5_head.S                       | 302 ++++++++
 arch/ceva/src/xc5/xc5_icache.c                     | 294 ++++++++
 arch/ceva/src/xc5/xc5_initialstate.c               | 107 +++
 arch/ceva/src/xc5/xc5_intc.c                       | 201 ++++++
 arch/ceva/src/xc5/xc5_mpu.c                        | 130 ++++
 arch/ceva/src/xc5/xc5_psu.c                        |  73 ++
 arch/ceva/src/xc5/xc5_relocate.c                   |  87 +++
 arch/ceva/src/xc5/xc5_signal_handler.S             |  99 +++
 arch/ceva/src/xc5/xc5_svcall_handler.S             | 110 +++
 arch/ceva/src/xm6/up_hardfault.c                   | 111 ---
 arch/ceva/src/xm6/up_head.S                        | 229 -------
 arch/ceva/src/xm6/up_icache.c                      | 298 --------
 arch/ceva/src/xm6/up_initialstate.c                | 115 ----
 arch/ceva/src/xm6/up_intc.c                        | 217 ------
 arch/ceva/src/xm6/up_mpu.c                         | 130 ----
 arch/ceva/src/xm6/up_psu.c                         |  69 --
 arch/ceva/src/xm6/up_signal_handler.S              |  96 ---
 arch/ceva/src/xm6/up_svcall_handler.S              | 103 ---
 arch/ceva/src/xm6/xm6_hardfault.c                  | 111 +++
 arch/ceva/src/xm6/xm6_head.S                       | 229 +++++++
 arch/ceva/src/xm6/xm6_icache.c                     | 298 ++++++++
 arch/ceva/src/xm6/xm6_initialstate.c               | 115 ++++
 arch/ceva/src/xm6/xm6_intc.c                       | 217 ++++++
 arch/ceva/src/xm6/xm6_mpu.c                        | 130 ++++
 arch/ceva/src/xm6/xm6_psu.c                        |  69 ++
 arch/ceva/src/xm6/xm6_signal_handler.S             |  96 +++
 arch/ceva/src/xm6/xm6_svcall_handler.S             | 103 +++
 arch/hc/src/common/hc_allocateheap.c               |  71 ++
 arch/hc/src/common/hc_blocktask.c                  | 120 ++++
 arch/hc/src/common/hc_copystate.c                  |  66 ++
 arch/hc/src/common/hc_createstack.c                | 211 ++++++
 arch/hc/src/common/hc_doirq.c                      | 121 ++++
 arch/hc/src/common/hc_exit.c                       | 149 ++++
 arch/hc/src/common/hc_idle.c                       |  69 ++
 arch/hc/src/common/hc_initialize.c                 | 101 +++
 arch/hc/src/common/hc_internal.h                   | 200 ++++++
 arch/hc/src/common/hc_mdelay.c                     |  75 ++
 arch/hc/src/common/hc_modifyreg16.c                |  70 ++
 arch/hc/src/common/hc_modifyreg32.c                |  70 ++
 arch/hc/src/common/hc_modifyreg8.c                 |  70 ++
 arch/hc/src/common/hc_nputs.c                      |  58 ++
 arch/hc/src/common/hc_releasepending.c             | 127 ++++
 arch/hc/src/common/hc_releasestack.c               | 106 +++
 arch/hc/src/common/hc_stackframe.c                 |  98 +++
 arch/hc/src/common/hc_udelay.c                     | 118 ++++
 arch/hc/src/common/hc_unblocktask.c                | 108 +++
 arch/hc/src/common/hc_usestack.c                   | 125 ++++
 arch/hc/src/common/up_allocateheap.c               |  71 --
 arch/hc/src/common/up_blocktask.c                  | 120 ----
 arch/hc/src/common/up_copystate.c                  |  66 --
 arch/hc/src/common/up_createstack.c                | 211 ------
 arch/hc/src/common/up_doirq.c                      | 121 ----
 arch/hc/src/common/up_exit.c                       | 149 ----
 arch/hc/src/common/up_idle.c                       |  69 --
 arch/hc/src/common/up_initialize.c                 | 101 ---
 arch/hc/src/common/up_internal.h                   | 200 ------
 arch/hc/src/common/up_mdelay.c                     |  75 --
 arch/hc/src/common/up_modifyreg16.c                |  70 --
 arch/hc/src/common/up_modifyreg32.c                |  70 --
 arch/hc/src/common/up_modifyreg8.c                 |  70 --
 arch/hc/src/common/up_nputs.c                      |  58 --
 arch/hc/src/common/up_releasepending.c             | 127 ----
 arch/hc/src/common/up_releasestack.c               | 106 ---
 arch/hc/src/common/up_stackframe.c                 |  98 ---
 arch/hc/src/common/up_udelay.c                     | 118 ----
 arch/hc/src/common/up_unblocktask.c                | 108 ---
 arch/hc/src/common/up_usestack.c                   | 125 ----
 arch/hc/src/m9s12/Make.defs                        |  10 +-
 arch/hc/src/m9s12/m9s12.h                          |   4 +-
 arch/hc/src/m9s12/m9s12_assert.c                   |   2 +-
 arch/hc/src/m9s12/m9s12_dumpgpio.c                 |   2 +-
 arch/hc/src/m9s12/m9s12_gpio.c                     |   2 +-
 arch/hc/src/m9s12/m9s12_gpioirq.c                  |   2 +-
 arch/hc/src/m9s12/m9s12_initialstate.c             |   2 +-
 arch/hc/src/m9s12/m9s12_irq.c                      |   2 +-
 arch/hc/src/m9s12/m9s12_lowputc.S                  |  12 +-
 arch/hc/src/m9s12/m9s12_saveusercontext.S          |   2 +-
 arch/hc/src/m9s12/m9s12_serial.c                   |  18 +-
 arch/hc/src/m9s12/m9s12_start.S                    |   2 +-
 arch/hc/src/m9s12/m9s12_timerisr.c                 |   2 +-
 arch/hc/src/m9s12/m9s12_vectors.S                  |  18 +-
 arch/mips/include/syscall.h                        |   4 +-
 arch/mips/src/common/mips_etherstub.c              |  10 +-
 arch/mips/src/common/mips_initialize.c             |  16 +-
 arch/mips/src/common/mips_internal.h               |  50 +-
 arch/mips/src/common/mips_lowputs.c                |   6 +-
 arch/mips/src/mips32/mips_assert.c                 |   2 +-
 arch/mips/src/mips32/mips_blocktask.c              |   8 +-
 arch/mips/src/mips32/mips_copystate.c              |   4 +-
 arch/mips/src/mips32/mips_doirq.c                  |   2 +-
 arch/mips/src/mips32/mips_dumpstate.c              |   4 +-
 arch/mips/src/mips32/mips_releasepending.c         |   8 +-
 arch/mips/src/mips32/mips_schedulesigaction.c      |   6 +-
 arch/mips/src/mips32/mips_sigdeliver.c             |   6 +-
 arch/mips/src/mips32/mips_swint0.c                 |  11 +-
 arch/mips/src/mips32/mips_unblocktask.c            |   8 +-
 arch/mips/src/pic32mx/Make.defs                    |   4 +-
 arch/mips/src/pic32mx/pic32mx_ethernet.c           |  12 +-
 arch/mips/src/pic32mx/pic32mx_gpioirq.c            |   2 +-
 arch/mips/src/pic32mx/pic32mx_irq.c                |  16 +-
 arch/mips/src/pic32mx/pic32mx_lowconsole.c         |   4 +-
 arch/mips/src/pic32mx/pic32mx_lowinit.c            |   2 +-
 arch/mips/src/pic32mx/pic32mx_serial.c             |  42 +-
 arch/mips/src/pic32mx/pic32mx_timerisr.c           |   2 +-
 arch/mips/src/pic32mx/pic32mx_usbdev.c             |  12 +-
 arch/mips/src/pic32mz/Make.defs                    |   4 +-
 arch/mips/src/pic32mz/pic32mz_dma.c                |  12 +-
 arch/mips/src/pic32mz/pic32mz_ethernet.c           |  12 +-
 arch/mips/src/pic32mz/pic32mz_gpioirq.c            |   4 +-
 arch/mips/src/pic32mz/pic32mz_head.S               |   4 +-
 arch/mips/src/pic32mz/pic32mz_i2c.c                |  12 +-
 arch/mips/src/pic32mz/pic32mz_irq.c                |  16 +-
 arch/mips/src/pic32mz/pic32mz_lowconsole.c         |   4 +-
 arch/mips/src/pic32mz/pic32mz_lowinit.c            |   2 +-
 arch/mips/src/pic32mz/pic32mz_serial.c             |  42 +-
 arch/mips/src/pic32mz/pic32mz_timer.c              |   8 +-
 arch/mips/src/pic32mz/pic32mz_timerisr.c           |   4 +-
 arch/misoc/include/syscall.h                       |   4 +-
 arch/misoc/src/common/misoc.h                      |   4 +-
 arch/misoc/src/lm32/lm32.h                         |   4 +-
 arch/misoc/src/lm32/lm32_blocktask.c               |   8 +-
 arch/misoc/src/lm32/lm32_releasepending.c          |   8 +-
 arch/misoc/src/lm32/lm32_schedulesigaction.c       |   2 +-
 arch/misoc/src/lm32/lm32_swint.c                   |   3 +-
 arch/misoc/src/lm32/lm32_unblocktask.c             |   8 +-
 arch/misoc/src/minerva/minerva.h                   |   4 +-
 arch/misoc/src/minerva/minerva_blocktask.c         |   8 +-
 arch/misoc/src/minerva/minerva_releasepending.c    |  14 +-
 arch/misoc/src/minerva/minerva_schedulesigaction.c |   2 +-
 arch/misoc/src/minerva/minerva_swint.c             |   4 +-
 arch/misoc/src/minerva/minerva_unblocktask.c       |   8 +-
 arch/or1k/src/common/or1k_allocateheap.c           | 163 +++++
 arch/or1k/src/common/or1k_assert.c                 | 373 ++++++++++
 arch/or1k/src/common/or1k_blocktask.c              | 120 ++++
 arch/or1k/src/common/or1k_checkstack.c             | 150 ++++
 arch/or1k/src/common/or1k_copyfullstate.c          |  50 ++
 arch/or1k/src/common/or1k_cpuinfo.c                | 126 ++++
 arch/or1k/src/common/or1k_createstack.c            | 238 +++++++
 arch/or1k/src/common/or1k_doirq.c                  |  83 +++
 arch/or1k/src/common/or1k_etherstub.c              |  55 ++
 arch/or1k/src/common/or1k_exit.c                   | 150 ++++
 arch/or1k/src/common/or1k_fullcontextrestore.S     |  95 +++
 arch/or1k/src/common/or1k_idle.c                   |  63 ++
 arch/or1k/src/common/or1k_initialize.c             | 216 ++++++
 arch/or1k/src/common/or1k_initialstate.c           | 130 ++++
 arch/or1k/src/common/or1k_internal.h               | 332 +++++++++
 arch/or1k/src/common/or1k_lowputs.c                |  47 ++
 arch/or1k/src/common/or1k_mdelay.c                 |  55 ++
 arch/or1k/src/common/or1k_modifyreg16.c            |  57 ++
 arch/or1k/src/common/or1k_modifyreg32.c            |  57 ++
 arch/or1k/src/common/or1k_modifyreg8.c             |  57 ++
 arch/or1k/src/common/or1k_nputs.c                  |  46 ++
 arch/or1k/src/common/or1k_pthread_start.c          |  78 +++
 arch/or1k/src/common/or1k_releasepending.c         | 128 ++++
 arch/or1k/src/common/or1k_releasestack.c           | 102 +++
 arch/or1k/src/common/or1k_saveusercontext.S        |  90 +++
 arch/or1k/src/common/or1k_schedulesigaction.c      | 172 +++++
 arch/or1k/src/common/or1k_stackframe.c             |  98 +++
 arch/or1k/src/common/or1k_task_start.c             |  76 +++
 arch/or1k/src/common/or1k_timer.c                  | 110 +++
 arch/or1k/src/common/or1k_uart.c                   |  45 ++
 arch/or1k/src/common/or1k_udelay.c                 | 102 +++
 arch/or1k/src/common/or1k_unblocktask.c            | 112 +++
 arch/or1k/src/common/or1k_usestack.c               | 113 +++
 arch/or1k/src/common/up_allocateheap.c             | 163 -----
 arch/or1k/src/common/up_assert.c                   | 373 ----------
 arch/or1k/src/common/up_blocktask.c                | 120 ----
 arch/or1k/src/common/up_checkstack.c               | 150 ----
 arch/or1k/src/common/up_copyfullstate.c            |  50 --
 arch/or1k/src/common/up_cpuinfo.c                  | 126 ----
 arch/or1k/src/common/up_createstack.c              | 238 -------
 arch/or1k/src/common/up_doirq.c                    |  83 ---
 arch/or1k/src/common/up_etherstub.c                |  55 --
 arch/or1k/src/common/up_exit.c                     | 150 ----
 arch/or1k/src/common/up_fullcontextrestore.S       |  95 ---
 arch/or1k/src/common/up_idle.c                     |  63 --
 arch/or1k/src/common/up_initialize.c               | 216 ------
 arch/or1k/src/common/up_initialstate.c             | 130 ----
 arch/or1k/src/common/up_internal.h                 | 332 ---------
 arch/or1k/src/common/up_lowputs.c                  |  47 --
 arch/or1k/src/common/up_mdelay.c                   |  55 --
 arch/or1k/src/common/up_modifyreg16.c              |  57 --
 arch/or1k/src/common/up_modifyreg32.c              |  57 --
 arch/or1k/src/common/up_modifyreg8.c               |  57 --
 arch/or1k/src/common/up_nputs.c                    |  46 --
 arch/or1k/src/common/up_pthread_start.c            |  78 ---
 arch/or1k/src/common/up_releasepending.c           | 128 ----
 arch/or1k/src/common/up_releasestack.c             | 102 ---
 arch/or1k/src/common/up_saveusercontext.S          |  90 ---
 arch/or1k/src/common/up_schedulesigaction.c        | 172 -----
 arch/or1k/src/common/up_stackframe.c               |  98 ---
 arch/or1k/src/common/up_task_start.c               |  76 ---
 arch/or1k/src/common/up_timer.c                    | 110 ---
 arch/or1k/src/common/up_uart.c                     |  45 --
 arch/or1k/src/common/up_udelay.c                   | 102 ---
 arch/or1k/src/common/up_unblocktask.c              | 112 ---
 arch/or1k/src/common/up_usestack.c                 | 113 ---
 arch/or1k/src/mor1kx/Make.defs                     |  62 +-
 arch/or1k/src/mor1kx/mor1kx_serial.c               |  10 +-
 arch/or1k/src/mor1kx/mor1kx_start.c                |   4 +-
 arch/or1k/src/mor1kx/or1k_irq.c                    | 144 ++++
 arch/or1k/src/mor1kx/or1k_vectortab.S              | 409 +++++++++++
 arch/or1k/src/mor1kx/up_irq.c                      | 144 ----
 arch/or1k/src/mor1kx/up_vectortab.S                | 409 -----------
 arch/renesas/src/common/renesas_allocateheap.c     |  72 ++
 arch/renesas/src/common/renesas_assert.c           | 165 +++++
 arch/renesas/src/common/renesas_blocktask.c        | 120 ++++
 arch/renesas/src/common/renesas_createstack.c      | 212 ++++++
 arch/renesas/src/common/renesas_doirq.c            | 124 ++++
 arch/renesas/src/common/renesas_exit.c             | 149 ++++
 arch/renesas/src/common/renesas_idle.c             |  71 ++
 arch/renesas/src/common/renesas_initialize.c       |  90 +++
 arch/renesas/src/common/renesas_internal.h         | 203 ++++++
 arch/renesas/src/common/renesas_lowputs.c          |  59 ++
 arch/renesas/src/common/renesas_mdelay.c           |  75 ++
 arch/renesas/src/common/renesas_nputs.c            |  58 ++
 arch/renesas/src/common/renesas_releasepending.c   | 128 ++++
 arch/renesas/src/common/renesas_releasestack.c     | 106 +++
 arch/renesas/src/common/renesas_stackframe.c       |  97 +++
 arch/renesas/src/common/renesas_udelay.c           | 118 ++++
 arch/renesas/src/common/renesas_unblocktask.c      | 108 +++
 arch/renesas/src/common/renesas_usestack.c         | 124 ++++
 arch/renesas/src/common/up_allocateheap.c          |  72 --
 arch/renesas/src/common/up_assert.c                | 165 -----
 arch/renesas/src/common/up_blocktask.c             | 120 ----
 arch/renesas/src/common/up_createstack.c           | 212 ------
 arch/renesas/src/common/up_doirq.c                 | 124 ----
 arch/renesas/src/common/up_exit.c                  | 149 ----
 arch/renesas/src/common/up_idle.c                  |  71 --
 arch/renesas/src/common/up_initialize.c            |  90 ---
 arch/renesas/src/common/up_internal.h              | 203 ------
 arch/renesas/src/common/up_lowputs.c               |  59 --
 arch/renesas/src/common/up_mdelay.c                |  75 --
 arch/renesas/src/common/up_nputs.c                 |  58 --
 arch/renesas/src/common/up_releasepending.c        | 128 ----
 arch/renesas/src/common/up_releasestack.c          | 106 ---
 arch/renesas/src/common/up_stackframe.c            |  97 ---
 arch/renesas/src/common/up_udelay.c                | 118 ----
 arch/renesas/src/common/up_unblocktask.c           | 108 ---
 arch/renesas/src/common/up_usestack.c              | 124 ----
 arch/renesas/src/m16c/Make.defs                    |  10 +-
 arch/renesas/src/m16c/m16c_copystate.c             |   6 +-
 arch/renesas/src/m16c/m16c_dumpstate.c             |   6 +-
 arch/renesas/src/m16c/m16c_head.S                  |  10 +-
 arch/renesas/src/m16c/m16c_initialstate.c          |   2 +-
 arch/renesas/src/m16c/m16c_irq.c                   |   2 +-
 arch/renesas/src/m16c/m16c_lowputc.c               |   8 +-
 arch/renesas/src/m16c/m16c_schedulesigaction.c     |  12 +-
 arch/renesas/src/m16c/m16c_serial.c                |  18 +-
 arch/renesas/src/m16c/m16c_sigdeliver.c            |  10 +-
 arch/renesas/src/m16c/m16c_timerisr.c              |   2 +-
 arch/renesas/src/m16c/m16c_vectors.S               |  14 +-
 arch/renesas/src/rx65n/Make.defs                   |  10 +-
 arch/renesas/src/rx65n/rx65n_copystate.c           |   6 +-
 arch/renesas/src/rx65n/rx65n_dtc.c                 |   2 +-
 arch/renesas/src/rx65n/rx65n_dumpstate.c           |   6 +-
 arch/renesas/src/rx65n/rx65n_eth.c                 |   8 +-
 arch/renesas/src/rx65n/rx65n_hardware_setup.c      |   2 +-
 arch/renesas/src/rx65n/rx65n_head.S                |  12 +-
 arch/renesas/src/rx65n/rx65n_initialstate.c        |   2 +-
 arch/renesas/src/rx65n/rx65n_irq.c                 |   2 +-
 arch/renesas/src/rx65n/rx65n_lowputc.c             |   6 +-
 arch/renesas/src/rx65n/rx65n_riic.c                |   2 +-
 arch/renesas/src/rx65n/rx65n_rspi.c                |   2 +-
 arch/renesas/src/rx65n/rx65n_rspi_sw.c             |   2 +-
 arch/renesas/src/rx65n/rx65n_rtc.c                 |   2 +-
 arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c       |   2 +-
 arch/renesas/src/rx65n/rx65n_schedulesigaction.c   |   8 +-
 arch/renesas/src/rx65n/rx65n_sci.c                 |   2 +-
 arch/renesas/src/rx65n/rx65n_serial.c              |  18 +-
 arch/renesas/src/rx65n/rx65n_sigdeliver.c          |  10 +-
 arch/renesas/src/rx65n/rx65n_timerisr.c            |   2 +-
 arch/renesas/src/rx65n/rx65n_usbdev.c              |  10 +-
 arch/renesas/src/rx65n/rx65n_usbhost.c             |   2 +-
 arch/renesas/src/rx65n/rx65n_vector.S              |  18 +-
 arch/renesas/src/sh1/Make.defs                     |  12 +-
 arch/renesas/src/sh1/sh1_copystate.c               |   6 +-
 arch/renesas/src/sh1/sh1_dumpstate.c               |   6 +-
 arch/renesas/src/sh1/sh1_head.S                    |  14 +-
 arch/renesas/src/sh1/sh1_initialstate.c            |   2 +-
 arch/renesas/src/sh1/sh1_irq.c                     |   2 +-
 arch/renesas/src/sh1/sh1_lowputc.c                 |   6 +-
 arch/renesas/src/sh1/sh1_saveusercontext.S         |   2 +-
 arch/renesas/src/sh1/sh1_schedulesigaction.c       |   8 +-
 arch/renesas/src/sh1/sh1_serial.c                  |  18 +-
 arch/renesas/src/sh1/sh1_sigdeliver.c              |  10 +-
 arch/renesas/src/sh1/sh1_timerisr.c                |   2 +-
 arch/renesas/src/sh1/sh1_vector.S                  |  16 +-
 arch/risc-v/src/c906/c906_allocateheap.c           |   6 +-
 arch/risc-v/src/mpfs/mpfs_allocateheap.c           |   6 +-
 arch/risc-v/src/qemu-rv/qemu_rv_allocateheap.c     |   6 +-
 arch/sim/src/Makefile                              | 110 +--
 arch/sim/src/sim/posix/sim_hcisocket_host.c        | 238 +++++++
 arch/sim/src/sim/posix/sim_hostfs.c                | 672 ++++++++++++++++++
 arch/sim/src/sim/posix/sim_hostirq.c               | 160 +++++
 arch/sim/src/sim/posix/sim_hostmemory.c            | 207 ++++++
 arch/sim/src/sim/posix/sim_hostmisc.c              |  72 ++
 arch/sim/src/sim/posix/sim_hosttime.c              | 121 ++++
 arch/sim/src/sim/posix/sim_i2cbus.h                |  80 +++
 arch/sim/src/sim/posix/sim_i2cbuslinux.c           | 310 +++++++++
 arch/sim/src/sim/posix/sim_simsmp.c                | 264 +++++++
 arch/sim/src/sim/posix/sim_simuart.c               | 212 ++++++
 arch/sim/src/sim/posix/sim_spi.h                   | 156 +++++
 arch/sim/src/sim/posix/sim_spilinux.c              | 732 ++++++++++++++++++++
 arch/sim/src/sim/posix/sim_tapdev.c                | 476 +++++++++++++
 arch/sim/src/sim/posix/sim_testset.c               |  72 ++
 arch/sim/src/sim/posix/sim_usrsock_host.c          | 522 ++++++++++++++
 arch/sim/src/sim/posix/sim_vpnkit.c                | 259 +++++++
 arch/sim/src/sim/posix/sim_wpcap.c                 | 338 +++++++++
 arch/sim/src/sim/posix/sim_x11eventloop.c          | 149 ++++
 arch/sim/src/sim/posix/sim_x11framebuffer.c        | 457 +++++++++++++
 arch/sim/src/sim/posix/up_hcisocket_host.c         | 238 -------
 arch/sim/src/sim/posix/up_hostfs.c                 | 672 ------------------
 arch/sim/src/sim/posix/up_hostirq.c                | 160 -----
 arch/sim/src/sim/posix/up_hostmemory.c             | 207 ------
 arch/sim/src/sim/posix/up_hostmisc.c               |  72 --
 arch/sim/src/sim/posix/up_hosttime.c               | 121 ----
 arch/sim/src/sim/posix/up_i2cbus.h                 |  80 ---
 arch/sim/src/sim/posix/up_i2cbuslinux.c            | 310 ---------
 arch/sim/src/sim/posix/up_simsmp.c                 | 264 -------
 arch/sim/src/sim/posix/up_simuart.c                | 212 ------
 arch/sim/src/sim/posix/up_spi.h                    | 156 -----
 arch/sim/src/sim/posix/up_spilinux.c               | 732 --------------------
 arch/sim/src/sim/posix/up_tapdev.c                 | 475 -------------
 arch/sim/src/sim/posix/up_testset.c                |  72 --
 arch/sim/src/sim/posix/up_usrsock_host.c           | 522 --------------
 arch/sim/src/sim/posix/up_vpnkit.c                 | 259 -------
 arch/sim/src/sim/posix/up_wpcap.c                  | 338 ---------
 arch/sim/src/sim/posix/up_x11eventloop.c           | 149 ----
 arch/sim/src/sim/posix/up_x11framebuffer.c         | 457 -------------
 arch/sim/src/sim/sim_ajoystick.c                   | 246 +++++++
 arch/sim/src/sim/sim_alsa.c                        | 756 +++++++++++++++++++++
 arch/sim/src/sim/sim_assert.c                      | 128 ++++
 arch/sim/src/sim/sim_backtrace.c                   |  55 ++
 arch/sim/src/sim/sim_blockdevice.c                 |  58 ++
 arch/sim/src/sim/sim_blocktask.c                   | 104 +++
 arch/sim/src/sim/sim_checkstack.c                  | 174 +++++
 arch/sim/src/sim/sim_copyfullstate.c               |  60 ++
 arch/sim/src/sim/sim_cpuidlestack.c                |  82 +++
 arch/sim/src/sim/sim_createstack.c                 | 194 ++++++
 arch/sim/src/sim/sim_deviceimage.c                 | 432 ++++++++++++
 arch/sim/src/sim/sim_exit.c                        |  90 +++
 arch/sim/src/sim/sim_framebuffer.c                 | 434 ++++++++++++
 arch/sim/src/sim/sim_hcisocket.c                   | 327 +++++++++
 arch/sim/src/sim/sim_hcisocket_host.h              |  41 ++
 arch/sim/src/sim/sim_head.c                        | 163 +++++
 arch/sim/src/sim/sim_heap.c                        | 464 +++++++++++++
 arch/sim/src/sim/sim_idle.c                        |  90 +++
 arch/sim/src/sim/sim_initialize.c                  | 277 ++++++++
 arch/sim/src/sim/sim_initialstate.c                | 101 +++
 arch/sim/src/sim/sim_internal.h                    | 368 ++++++++++
 arch/sim/src/sim/sim_interruptcontext.c            |  99 +++
 arch/sim/src/sim/sim_keyboard.c                    | 115 ++++
 arch/sim/src/sim/sim_lcd.c                         | 503 ++++++++++++++
 arch/sim/src/sim/sim_macho_init.c                  | 133 ++++
 arch/sim/src/sim/sim_netdriver.c                   | 458 +++++++++++++
 arch/sim/src/sim/sim_nputs.c                       |  58 ++
 arch/sim/src/sim/sim_oneshot.c                     | 450 ++++++++++++
 arch/sim/src/sim/sim_releasepending.c              | 114 ++++
 arch/sim/src/sim/sim_releasestack.c                |  76 +++
 arch/sim/src/sim/sim_romgetc.c                     |  71 ++
 arch/sim/src/sim/sim_rptun.c                       | 277 ++++++++
 arch/sim/src/sim/sim_rtc.c                         | 137 ++++
 arch/sim/src/sim/sim_schedulesigaction.c           |  96 +++
 arch/sim/src/sim/sim_sigdeliver.c                  | 141 ++++
 arch/sim/src/sim/sim_smpsignal.c                   | 398 +++++++++++
 arch/sim/src/sim/sim_stackframe.c                  |  98 +++
 arch/sim/src/sim/sim_touchscreen.c                 | 255 +++++++
 arch/sim/src/sim/sim_uart.c                        | 584 ++++++++++++++++
 arch/sim/src/sim/sim_unblocktask.c                 | 116 ++++
 arch/sim/src/sim/sim_usestack.c                    | 120 ++++
 arch/sim/src/sim/sim_usrsock.c                     | 430 ++++++++++++
 arch/sim/src/sim/sim_usrsock_host.h                | 317 +++++++++
 arch/sim/src/sim/sim_vfork.c                       | 169 +++++
 arch/sim/src/sim/sim_vfork_arm.S                   |  99 +++
 arch/sim/src/sim/sim_vfork_arm64.S                 | 116 ++++
 arch/sim/src/sim/sim_vfork_x86.S                   | 111 +++
 arch/sim/src/sim/sim_vfork_x86_64.S                | 115 ++++
 arch/sim/src/sim/up_ajoystick.c                    | 246 -------
 arch/sim/src/sim/up_alsa.c                         | 756 ---------------------
 arch/sim/src/sim/up_assert.c                       | 128 ----
 arch/sim/src/sim/up_backtrace.c                    |  55 --
 arch/sim/src/sim/up_blockdevice.c                  |  58 --
 arch/sim/src/sim/up_blocktask.c                    | 104 ---
 arch/sim/src/sim/up_checkstack.c                   | 174 -----
 arch/sim/src/sim/up_copyfullstate.c                |  60 --
 arch/sim/src/sim/up_cpuidlestack.c                 |  82 ---
 arch/sim/src/sim/up_createstack.c                  | 194 ------
 arch/sim/src/sim/up_deviceimage.c                  | 432 ------------
 arch/sim/src/sim/up_exit.c                         |  90 ---
 arch/sim/src/sim/up_framebuffer.c                  | 434 ------------
 arch/sim/src/sim/up_hcisocket.c                    | 327 ---------
 arch/sim/src/sim/up_hcisocket_host.h               |  41 --
 arch/sim/src/sim/up_head.c                         | 163 -----
 arch/sim/src/sim/up_heap.c                         | 464 -------------
 arch/sim/src/sim/up_idle.c                         |  90 ---
 arch/sim/src/sim/up_initialize.c                   | 277 --------
 arch/sim/src/sim/up_initialstate.c                 | 101 ---
 arch/sim/src/sim/up_internal.h                     | 368 ----------
 arch/sim/src/sim/up_interruptcontext.c             |  99 ---
 arch/sim/src/sim/up_keyboard.c                     | 115 ----
 arch/sim/src/sim/up_lcd.c                          | 503 --------------
 arch/sim/src/sim/up_macho_init.c                   | 133 ----
 arch/sim/src/sim/up_netdriver.c                    | 458 -------------
 arch/sim/src/sim/up_nputs.c                        |  58 --
 arch/sim/src/sim/up_oneshot.c                      | 450 ------------
 arch/sim/src/sim/up_releasepending.c               | 114 ----
 arch/sim/src/sim/up_releasestack.c                 |  76 ---
 arch/sim/src/sim/up_romgetc.c                      |  71 --
 arch/sim/src/sim/up_rptun.c                        | 276 --------
 arch/sim/src/sim/up_rtc.c                          | 137 ----
 arch/sim/src/sim/up_schedulesigaction.c            |  96 ---
 arch/sim/src/sim/up_sigdeliver.c                   | 141 ----
 arch/sim/src/sim/up_smpsignal.c                    | 398 -----------
 arch/sim/src/sim/up_stackframe.c                   |  98 ---
 arch/sim/src/sim/up_touchscreen.c                  | 255 -------
 arch/sim/src/sim/up_uart.c                         | 584 ----------------
 arch/sim/src/sim/up_unblocktask.c                  | 116 ----
 arch/sim/src/sim/up_usestack.c                     | 120 ----
 arch/sim/src/sim/up_usrsock.c                      | 430 ------------
 arch/sim/src/sim/up_usrsock_host.h                 | 317 ---------
 arch/sim/src/sim/up_vfork.c                        | 169 -----
 arch/sim/src/sim/up_vfork_arm.S                    |  99 ---
 arch/sim/src/sim/up_vfork_arm64.S                  | 116 ----
 arch/sim/src/sim/up_vfork_x86.S                    | 111 ---
 arch/sim/src/sim/up_vfork_x86_64.S                 | 115 ----
 arch/sim/src/sim/vpnkit/negotiate.c                | 127 ----
 arch/sim/src/sim/vpnkit/protocol.c                 | 326 ---------
 arch/sim/src/sim/vpnkit/protocol.h                 | 159 -----
 arch/sim/src/sim/vpnkit/sim_negotiate.c            | 127 ++++
 arch/sim/src/sim/vpnkit/sim_protocol.c             | 326 +++++++++
 arch/sim/src/sim/vpnkit/sim_protocol.h             | 159 +++++
 arch/sim/src/sim/win/sim_hostirq.c                 |  98 +++
 arch/sim/src/sim/win/sim_hostmemory.c              |  89 +++
 arch/sim/src/sim/win/sim_hostmisc.c                |  49 ++
 arch/sim/src/sim/win/sim_hosttime.c                | 133 ++++
 arch/sim/src/sim/win/sim_simuart.c                 | 142 ++++
 arch/sim/src/sim/win/up_hostirq.c                  |  98 ---
 arch/sim/src/sim/win/up_hostmemory.c               |  89 ---
 arch/sim/src/sim/win/up_hostmisc.c                 |  49 --
 arch/sim/src/sim/win/up_hosttime.c                 | 133 ----
 arch/sim/src/sim/win/up_simuart.c                  | 142 ----
 arch/sparc/include/syscall.h                       |  24 +-
 arch/sparc/src/bm3803/Make.defs                    |   2 +-
 arch/sparc/src/bm3803/bm3803-irq.c                 |  14 +-
 arch/sparc/src/bm3803/bm3803-lowconsole.c          |  10 +-
 arch/sparc/src/bm3803/bm3803-lowinit.c             |   8 +-
 arch/sparc/src/bm3803/bm3803-serial.c              |  36 +-
 arch/sparc/src/bm3803/bm3803-timerisr.c            |   6 +-
 arch/sparc/src/bm3803/bm3803.h                     |   6 +-
 arch/sparc/src/bm3803/bm3803_exceptions.S          |   4 +-
 arch/sparc/src/bm3803/bm3803_exti_gpio.c           |  10 +-
 arch/sparc/src/bm3803/bm3803_tim.c                 |   6 +-
 arch/sparc/src/bm3803/bm3803_wdg.c                 |   2 +-
 arch/sparc/src/bm3823/Make.defs                    |  12 +-
 arch/sparc/src/bm3823/bm3823-irq.c                 |  14 +-
 arch/sparc/src/bm3823/bm3823-lowconsole.c          |  10 +-
 arch/sparc/src/bm3823/bm3823-lowinit.c             |   8 +-
 arch/sparc/src/bm3823/bm3823-serial.c              |  36 +-
 arch/sparc/src/bm3823/bm3823-timerisr.c            |   6 +-
 arch/sparc/src/bm3823/bm3823.h                     |   6 +-
 arch/sparc/src/bm3823/bm3823_exceptions.S          |   4 +-
 arch/sparc/src/common/Make.defs                    |  22 +-
 arch/sparc/src/common/sparc_allocateheap.c         |  71 ++
 arch/sparc/src/common/sparc_assert.c               | 167 +++++
 arch/sparc/src/common/sparc_checkstack.c           | 234 +++++++
 arch/sparc/src/common/sparc_createstack.c          | 178 +++++
 arch/sparc/src/common/sparc_exit.c                 | 148 ++++
 arch/sparc/src/common/sparc_idle.c                 |  72 ++
 arch/sparc/src/common/sparc_initialize.c           | 190 ++++++
 arch/sparc/src/common/sparc_internal.h             | 267 ++++++++
 arch/sparc/src/common/sparc_lowputs.c              |  60 ++
 arch/sparc/src/common/sparc_mdelay.c               |  76 +++
 arch/sparc/src/common/sparc_modifyreg16.c          |  71 ++
 arch/sparc/src/common/sparc_modifyreg32.c          |  71 ++
 arch/sparc/src/common/sparc_modifyreg8.c           |  71 ++
 arch/sparc/src/common/sparc_nputs.c                |  58 ++
 arch/sparc/src/common/sparc_releasestack.c         | 107 +++
 arch/sparc/src/common/sparc_stackframe.c           |  99 +++
 arch/sparc/src/common/sparc_testset.c              | 104 +++
 arch/sparc/src/common/sparc_udelay.c               | 119 ++++
 arch/sparc/src/common/sparc_usestack.c             | 118 ++++
 arch/sparc/src/common/up_allocateheap.c            |  71 --
 arch/sparc/src/common/up_assert.c                  | 167 -----
 arch/sparc/src/common/up_checkstack.c              | 234 -------
 arch/sparc/src/common/up_createstack.c             | 178 -----
 arch/sparc/src/common/up_exit.c                    | 148 ----
 arch/sparc/src/common/up_idle.c                    |  72 --
 arch/sparc/src/common/up_initialize.c              | 190 ------
 arch/sparc/src/common/up_internal.h                | 267 --------
 arch/sparc/src/common/up_lowputs.c                 |  60 --
 arch/sparc/src/common/up_mdelay.c                  |  76 ---
 arch/sparc/src/common/up_modifyreg16.c             |  71 --
 arch/sparc/src/common/up_modifyreg32.c             |  71 --
 arch/sparc/src/common/up_modifyreg8.c              |  71 --
 arch/sparc/src/common/up_nputs.c                   |  58 --
 arch/sparc/src/common/up_releasestack.c            | 107 ---
 arch/sparc/src/common/up_stackframe.c              |  99 ---
 arch/sparc/src/common/up_testset.c                 | 104 ---
 arch/sparc/src/common/up_udelay.c                  | 119 ----
 arch/sparc/src/common/up_usestack.c                | 118 ----
 arch/sparc/src/s698pm/Make.defs                    |   2 +-
 arch/sparc/src/s698pm/s698pm-irq.c                 |  18 +-
 arch/sparc/src/s698pm/s698pm-lowconsole.c          |   6 +-
 arch/sparc/src/s698pm/s698pm-lowinit.c             |   6 +-
 arch/sparc/src/s698pm/s698pm-serial.c              |  36 +-
 arch/sparc/src/s698pm/s698pm-timerisr.c            |   6 +-
 arch/sparc/src/s698pm/s698pm_cpuidlestack.c        |   2 +-
 arch/sparc/src/s698pm/s698pm_cpuindex.c            |   2 +-
 arch/sparc/src/s698pm/s698pm_cpupause.c            |   6 +-
 arch/sparc/src/s698pm/s698pm_cpustart.c            |   2 +-
 arch/sparc/src/s698pm/s698pm_exceptions.S          |   4 +-
 arch/sparc/src/s698pm/s698pm_tim.c                 |   6 +-
 arch/sparc/src/sparc_v8/Make.defs                  |  36 +
 arch/sparc/src/sparc_v8/sparc_v8.h                 |  12 +-
 arch/sparc/src/sparc_v8/sparc_v8_blocktask.c       | 115 ++++
 arch/sparc/src/sparc_v8/sparc_v8_copystate.c       |  98 +++
 arch/sparc/src/sparc_v8/sparc_v8_doirq.c           | 130 ++++
 arch/sparc/src/sparc_v8/sparc_v8_dumpstate.c       | 216 ++++++
 arch/sparc/src/sparc_v8/sparc_v8_initialstate.c    | 122 ++++
 arch/sparc/src/sparc_v8/sparc_v8_irq.c             | 130 ++++
 arch/sparc/src/sparc_v8/sparc_v8_releasepending.c  | 118 ++++
 arch/sparc/src/sparc_v8/sparc_v8_romgetc.c         |  91 +++
 .../src/sparc_v8/sparc_v8_schedulesigaction.c      | 358 ++++++++++
 arch/sparc/src/sparc_v8/sparc_v8_sigdeliver.c      | 199 ++++++
 arch/sparc/src/sparc_v8/sparc_v8_swint1.c          | 241 +++++++
 arch/sparc/src/sparc_v8/sparc_v8_syscall.S         | 173 +++++
 arch/sparc/src/sparc_v8/sparc_v8_systemreset.c     |  61 ++
 arch/sparc/src/sparc_v8/sparc_v8_unblocktask.c     | 103 +++
 arch/sparc/src/sparc_v8/up_blocktask.c             | 115 ----
 arch/sparc/src/sparc_v8/up_copystate.c             |  98 ---
 arch/sparc/src/sparc_v8/up_doirq.c                 | 130 ----
 arch/sparc/src/sparc_v8/up_dumpstate.c             | 216 ------
 arch/sparc/src/sparc_v8/up_initialstate.c          | 122 ----
 arch/sparc/src/sparc_v8/up_irq.c                   | 130 ----
 arch/sparc/src/sparc_v8/up_releasepending.c        | 118 ----
 arch/sparc/src/sparc_v8/up_romgetc.c               |  91 ---
 arch/sparc/src/sparc_v8/up_schedulesigaction.c     | 358 ----------
 arch/sparc/src/sparc_v8/up_sigdeliver.c            | 199 ------
 arch/sparc/src/sparc_v8/up_swint1.c                | 239 -------
 arch/sparc/src/sparc_v8/up_syscall.S               | 173 -----
 arch/sparc/src/sparc_v8/up_systemreset.c           |  61 --
 arch/sparc/src/sparc_v8/up_unblocktask.c           | 103 ---
 arch/x86/src/common/up_allocateheap.c              |  72 --
 arch/x86/src/common/up_assert.c                    | 295 --------
 arch/x86/src/common/up_blocktask.c                 | 121 ----
 arch/x86/src/common/up_copystate.c                 |  66 --
 arch/x86/src/common/up_exit.c                      | 151 ----
 arch/x86/src/common/up_initialize.c                |  95 ---
 arch/x86/src/common/up_internal.h                  | 218 ------
 arch/x86/src/common/up_lowputs.c                   |  59 --
 arch/x86/src/common/up_mdelay.c                    |  75 --
 arch/x86/src/common/up_modifyreg16.c               |  70 --
 arch/x86/src/common/up_modifyreg32.c               |  70 --
 arch/x86/src/common/up_modifyreg8.c                |  70 --
 arch/x86/src/common/up_nputs.c                     |  58 --
 arch/x86/src/common/up_releasepending.c            | 128 ----
 arch/x86/src/common/up_udelay.c                    | 118 ----
 arch/x86/src/common/up_unblocktask.c               | 108 ---
 arch/x86/src/common/x86_allocateheap.c             |  72 ++
 arch/x86/src/common/x86_assert.c                   | 295 ++++++++
 arch/x86/src/common/x86_blocktask.c                | 121 ++++
 arch/x86/src/common/x86_copystate.c                |  66 ++
 arch/x86/src/common/x86_exit.c                     | 151 ++++
 arch/x86/src/common/x86_initialize.c               |  95 +++
 arch/x86/src/common/x86_internal.h                 | 217 ++++++
 arch/x86/src/common/x86_lowputs.c                  |  59 ++
 arch/x86/src/common/x86_mdelay.c                   |  75 ++
 arch/x86/src/common/x86_modifyreg16.c              |  70 ++
 arch/x86/src/common/x86_modifyreg32.c              |  70 ++
 arch/x86/src/common/x86_modifyreg8.c               |  70 ++
 arch/x86/src/common/x86_nputs.c                    |  58 ++
 arch/x86/src/common/x86_releasepending.c           | 128 ++++
 arch/x86/src/common/x86_udelay.c                   | 118 ++++
 arch/x86/src/common/x86_unblocktask.c              | 108 +++
 arch/x86/src/i486/i486_createstack.c               | 211 ++++++
 arch/x86/src/i486/i486_initialstate.c              | 123 ++++
 arch/x86/src/i486/i486_irq.c                       | 353 ++++++++++
 arch/x86/src/i486/i486_regdump.c                   |  51 ++
 arch/x86/src/i486/i486_releasestack.c              | 106 +++
 arch/x86/src/i486/i486_savestate.c                 | 100 +++
 arch/x86/src/i486/i486_schedulesigaction.c         | 163 +++++
 arch/x86/src/i486/i486_sigdeliver.c                | 107 +++
 arch/x86/src/i486/i486_stackframe.c                |  98 +++
 arch/x86/src/i486/i486_syscall6.S                  |  83 +++
 arch/x86/src/i486/i486_usestack.c                  | 124 ++++
 arch/x86/src/i486/up_createstack.c                 | 211 ------
 arch/x86/src/i486/up_initialstate.c                | 123 ----
 arch/x86/src/i486/up_irq.c                         | 353 ----------
 arch/x86/src/i486/up_regdump.c                     |  51 --
 arch/x86/src/i486/up_releasestack.c                | 106 ---
 arch/x86/src/i486/up_savestate.c                   | 100 ---
 arch/x86/src/i486/up_schedulesigaction.c           | 163 -----
 arch/x86/src/i486/up_sigdeliver.c                  | 107 ---
 arch/x86/src/i486/up_stackframe.c                  |  98 ---
 arch/x86/src/i486/up_syscall6.S                    |  83 ---
 arch/x86/src/i486/up_usestack.c                    | 124 ----
 arch/x86/src/qemu/Make.defs                        |  20 +-
 arch/x86/src/qemu/chip.h                           |   3 +
 arch/x86/src/qemu/qemu.h                           |   2 +-
 arch/x86/src/qemu/qemu_fullcontextrestore.S        |  14 +-
 arch/x86/src/qemu/qemu_handlers.c                  |   2 +-
 arch/x86/src/qemu/qemu_idle.c                      |   2 +-
 arch/x86/src/qemu/qemu_lowputc.c                   |   6 +-
 arch/x86/src/qemu/qemu_lowsetup.c                  |   4 +-
 arch/x86/src/qemu/qemu_saveusercontext.S           |   4 +-
 arch/x86/src/qemu/qemu_serial.c                    |  21 +-
 arch/x86/src/qemu/qemu_timerisr.c                  |   2 +-
 arch/x86/src/qemu/qemu_vectors.S                   |   6 +-
 arch/x86_64/src/common/up_allocateheap.c           |  82 ---
 arch/x86_64/src/common/up_assert.c                 | 284 --------
 arch/x86_64/src/common/up_blocktask.c              | 122 ----
 arch/x86_64/src/common/up_copystate.c              |  63 --
 arch/x86_64/src/common/up_exit.c                   | 155 -----
 arch/x86_64/src/common/up_initialize.c             | 126 ----
 arch/x86_64/src/common/up_internal.h               | 240 -------
 arch/x86_64/src/common/up_lowputs.c                |  59 --
 arch/x86_64/src/common/up_mdelay.c                 |  75 --
 arch/x86_64/src/common/up_modifyreg16.c            |  70 --
 arch/x86_64/src/common/up_modifyreg32.c            |  70 --
 arch/x86_64/src/common/up_modifyreg8.c             |  70 --
 arch/x86_64/src/common/up_nputs.c                  |  58 --
 arch/x86_64/src/common/up_releasepending.c         | 130 ----
 arch/x86_64/src/common/up_udelay.c                 | 102 ---
 arch/x86_64/src/common/up_unblocktask.c            | 114 ----
 arch/x86_64/src/common/x86_64_allocateheap.c       |  82 +++
 arch/x86_64/src/common/x86_64_assert.c             | 284 ++++++++
 arch/x86_64/src/common/x86_64_blocktask.c          | 122 ++++
 arch/x86_64/src/common/x86_64_copystate.c          |  63 ++
 arch/x86_64/src/common/x86_64_exit.c               | 155 +++++
 arch/x86_64/src/common/x86_64_initialize.c         | 126 ++++
 arch/x86_64/src/common/x86_64_internal.h           | 240 +++++++
 arch/x86_64/src/common/x86_64_lowputs.c            |  59 ++
 arch/x86_64/src/common/x86_64_mdelay.c             |  75 ++
 arch/x86_64/src/common/x86_64_modifyreg16.c        |  70 ++
 arch/x86_64/src/common/x86_64_modifyreg32.c        |  70 ++
 arch/x86_64/src/common/x86_64_modifyreg8.c         |  70 ++
 arch/x86_64/src/common/x86_64_nputs.c              |  58 ++
 arch/x86_64/src/common/x86_64_releasepending.c     | 130 ++++
 arch/x86_64/src/common/x86_64_udelay.c             | 102 +++
 arch/x86_64/src/common/x86_64_unblocktask.c        | 114 ++++
 arch/x86_64/src/intel64/Make.defs                  |  19 +-
 arch/x86_64/src/intel64/chip.h                     |   5 +
 arch/x86_64/src/intel64/intel64.h                  |   2 +-
 arch/x86_64/src/intel64/intel64_check_capability.c |   2 +-
 arch/x86_64/src/intel64/intel64_createstack.c      | 213 ++++++
 .../src/intel64/intel64_fullcontextrestore.S       |  14 +-
 arch/x86_64/src/intel64/intel64_handlers.c         |   4 +-
 arch/x86_64/src/intel64/intel64_idle.c             |   2 +-
 arch/x86_64/src/intel64/intel64_initialstate.c     | 142 ++++
 arch/x86_64/src/intel64/intel64_irq.c              | 565 +++++++++++++++
 arch/x86_64/src/intel64/intel64_lowsetup.c         |   4 +-
 arch/x86_64/src/intel64/intel64_map_region.c       |  76 +++
 arch/x86_64/src/intel64/intel64_regdump.c          | 158 +++++
 arch/x86_64/src/intel64/intel64_releasestack.c     | 108 +++
 arch/x86_64/src/intel64/intel64_restore_auxstate.c |  56 ++
 arch/x86_64/src/intel64/intel64_rng.c              |   2 +-
 arch/x86_64/src/intel64/intel64_rtc.c              | 174 +++++
 arch/x86_64/src/intel64/intel64_savestate.c        |  50 ++
 arch/x86_64/src/intel64/intel64_saveusercontext.S  |   2 +-
 .../x86_64/src/intel64/intel64_schedulesigaction.c | 166 +++++
 arch/x86_64/src/intel64/intel64_serial.c           |  17 +-
 arch/x86_64/src/intel64/intel64_sigdeliver.c       | 124 ++++
 arch/x86_64/src/intel64/intel64_stackframe.c       |  98 +++
 arch/x86_64/src/intel64/intel64_timerisr.c         |   2 +-
 arch/x86_64/src/intel64/intel64_usestack.c         | 126 ++++
 arch/x86_64/src/intel64/intel64_vectors.S          |   6 +-
 arch/x86_64/src/intel64/up_createstack.c           | 213 ------
 arch/x86_64/src/intel64/up_initialstate.c          | 142 ----
 arch/x86_64/src/intel64/up_irq.c                   | 565 ---------------
 arch/x86_64/src/intel64/up_map_region.c            |  76 ---
 arch/x86_64/src/intel64/up_regdump.c               | 158 -----
 arch/x86_64/src/intel64/up_releasestack.c          | 108 ---
 arch/x86_64/src/intel64/up_restore_auxstate.c      |  56 --
 arch/x86_64/src/intel64/up_rtc.c                   | 174 -----
 arch/x86_64/src/intel64/up_savestate.c             |  50 --
 arch/x86_64/src/intel64/up_schedulesigaction.c     | 166 -----
 arch/x86_64/src/intel64/up_sigdeliver.c            | 124 ----
 arch/x86_64/src/intel64/up_stackframe.c            |  98 ---
 arch/x86_64/src/intel64/up_usestack.c              | 126 ----
 arch/xtensa/src/common/xtensa.h                    |  16 +-
 arch/xtensa/src/common/xtensa_initialize.c         |   4 +-
 arch/xtensa/src/common/xtensa_lowputs.c            |   6 +-
 arch/xtensa/src/common/xtensa_swint.c              |   4 +-
 arch/xtensa/src/esp32/esp32_emac.c                 |   4 +-
 arch/xtensa/src/esp32/esp32_serial.c               |   4 +-
 arch/xtensa/src/esp32s2/esp32s2_lowputc.c          |   4 +-
 arch/xtensa/src/esp32s2/esp32s2_serial.c           |   6 +-
 arch/xtensa/src/esp32s2/esp32s2_start.c            |   2 +-
 arch/xtensa/src/esp32s3/esp32s3_lowputc.c          |   4 +-
 arch/xtensa/src/esp32s3/esp32s3_serial.c           |  10 +-
 arch/xtensa/src/esp32s3/esp32s3_start.c            |   2 +-
 arch/z16/src/common/z16_internal.h                 |   3 +-
 arch/z16/src/common/z16_registerdump.c             |   2 +-
 arch/z16/src/z16f/z16f_saveusercontext.S           |   6 +-
 arch/z80/src/common/z80_allocateheap.c             |   4 +-
 arch/z80/src/common/z80_initialize.c               |   4 +-
 arch/z80/src/common/z80_internal.h                 |  16 +-
 arch/z80/src/ez80/ez80_emac.c                      |  12 +-
 arch/z80/src/ez80/ez80_registerdump.c              |   2 +-
 arch/z80/src/ez80/ez80_saveusercontext.asm         |   6 +-
 arch/z80/src/ez80/ez80_timerisr.c                  |   2 +-
 arch/z80/src/ez80/switch.h                         |   4 +-
 arch/z80/src/z180/switch.h                         |   4 +-
 arch/z80/src/z180/z180_lowserial.c                 |   4 +-
 arch/z80/src/z180/z180_registerdump.c              |   2 +-
 arch/z80/src/z180/z180_saveusercontext.asm         |   4 +-
 arch/z80/src/z180/z180_scc.c                       |   2 +-
 arch/z80/src/z180/z180_serial.h                    |   6 +-
 arch/z80/src/z8/switch.h                           |   4 +-
 arch/z80/src/z8/z8_registerdump.c                  |   2 +-
 arch/z80/src/z8/z8_restorecontext.S                |   4 +-
 arch/z80/src/z8/z8_saveusercontext.S               |   6 +-
 arch/z80/src/z80/switch.h                          |   4 +-
 arch/z80/src/z80/z80_registerdump.c                |   2 +-
 arch/z80/src/z80/z80_saveusercontext.asm           |   4 +-
 boards/avr/at32uc3/avr32dev1/src/avr32_boot.c      |   2 +-
 .../avr/at90usb/micropendous3/src/at90usb_boot.c   |   2 +-
 boards/avr/at90usb/teensy-2.0/src/at90usb_boot.c   |   2 +-
 boards/avr/at90usb/teensy-2.0/src/at90usb_leds.c   |   2 +-
 boards/avr/at90usb/teensy-2.0/src/at90usb_spi.c    |   2 +-
 boards/avr/atmega/amber/src/atmega_boot.c          |   2 +-
 boards/avr/atmega/arduino-mega2560/src/avr_boot.c  |   2 +-
 boards/avr/atmega/arduino-mega2560/src/avr_leds.c  |   2 +-
 boards/avr/atmega/moteino-mega/src/avr_boot.c      |   2 +-
 boards/avr/atmega/moteino-mega/src/avr_leds.c      |   2 +-
 boards/or1k/mor1kx/or1k/src/or1k_autoled.c         |   2 +-
 boards/renesas/m16c/skp16c26/src/m16c_buttons.c    |   2 +-
 boards/renesas/m16c/skp16c26/src/m16c_lcd.c        |   2 +-
 boards/renesas/m16c/skp16c26/src/m16c_lcdconsole.c |   2 +-
 boards/renesas/m16c/skp16c26/src/m16c_leds.c       |   2 +-
 .../renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c   |   2 +-
 .../renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c   |   2 +-
 boards/renesas/sh1/us7032evb1/src/sh1_leds.c       |   2 +-
 boards/sim/sim/sim/src/sim_bringup.c               |  10 +-
 boards/sim/sim/sim/src/sim_buttons.c               |   2 +-
 boards/sparc/bm3803/xx3803/src/bm3803_boot.c       |   2 +-
 boards/sparc/bm3823/xx3823/src/bm3823_boot.c       |   2 +-
 boards/sparc/bm3823/xx3823/src/bm3823_leds.c       |   2 +-
 boards/x86/qemu/qemu-i486/src/qemu_appinit.c       |   2 +-
 boards/x86/qemu/qemu-i486/src/qemu_boot.c          |   2 +-
 .../x86_64/intel64/qemu-intel64/src/qemu_appinit.c |   2 +-
 boards/x86_64/intel64/qemu-intel64/src/qemu_boot.c |   2 +-
 boards/x86_64/intel64/qemu-intel64/src/qemu_net.c  |   2 +-
 945 files changed, 52254 insertions(+), 52188 deletions(-)

diff --git a/arch/arm/src/tlsr82/tc32/tc32_saveusercontext.S b/arch/arm/src/tlsr82/tc32/tc32_saveusercontext.S
index d98120c886..e2750ae7a8 100644
--- a/arch/arm/src/tlsr82/tc32/tc32_saveusercontext.S
+++ b/arch/arm/src/tlsr82/tc32/tc32_saveusercontext.S
@@ -41,12 +41,12 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: arm_saveusercontext
+ * Name: up_saveusercontext
  *
  * Description:
  *   Restore the current thread context.  Full prototype is:
  *
- *   int arm_saveusercontext(uint32_t *saveregs);
+ *   int up_saveusercontext(uint32_t *saveregs);
  *
  *   R0 = saveregs = pinter saved array
  *
diff --git a/arch/arm64/include/syscall.h b/arch/arm64/include/syscall.h
index 7a3e6f1822..3d019b1f4a 100644
--- a/arch/arm64/include/syscall.h
+++ b/arch/arm64/include/syscall.h
@@ -61,7 +61,7 @@
 
 /* SYS call 0:
  *
- * int arm64_saveusercontext(void *saveregs);
+ * int up_saveusercontext(void *saveregs);
  */
 
 #define SYS_save_context          (0)
diff --git a/arch/avr/src/at32uc3/Make.defs b/arch/avr/src/at32uc3/Make.defs
index 3455bdc9a7..111569f5c0 100644
--- a/arch/avr/src/at32uc3/Make.defs
+++ b/arch/avr/src/at32uc3/Make.defs
@@ -20,23 +20,23 @@
 
 # The start-up, "head", file
 
-HEAD_ASRC = up_nommuhead.S
+HEAD_ASRC = avr_nommuhead.S
 
 # Common AVR/AVR32 files
 
-CMN_ASRCS  = up_exceptions.S up_fullcontextrestore.S up_switchcontext.S
-CMN_CSRCS  = up_assert.c up_allocateheap.c up_blocktask.c up_copystate.c
-CMN_CSRCS += up_createstack.c up_mdelay.c up_udelay.c up_exit.c up_idle.c
-CMN_CSRCS += up_initialize.c up_initialstate.c
-CMN_CSRCS += up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c
-CMN_CSRCS += up_releasepending.c up_releasestack.c
-CMN_CSRCS += up_schedulesigaction.c up_sigdeliver.c up_stackframe.c
-CMN_CSRCS += up_unblocktask.c up_usestack.c up_doirq.c up_nputs.c
+CMN_ASRCS  = avr_exceptions.S avr_fullcontextrestore.S avr_switchcontext.S
+CMN_CSRCS  = avr_assert.c avr_allocateheap.c avr_blocktask.c avr_copystate.c
+CMN_CSRCS += avr_createstack.c avr_mdelay.c avr_udelay.c avr_exit.c avr_idle.c
+CMN_CSRCS += avr_initialize.c avr_initialstate.c
+CMN_CSRCS += avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c
+CMN_CSRCS += avr_releasepending.c avr_releasestack.c
+CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c avr_stackframe.c
+CMN_CSRCS += avr_unblocktask.c avr_usestack.c avr_doirq.c avr_nputs.c
 
 # Configuration-dependent common files
 
 ifeq ($(CONFIG_ARCH_STACKDUMP),y)
-CMN_CSRCS += up_dumpstate.c
+CMN_CSRCS += avr_dumpstate.c
 endif
 
 # Required AT32UC3 files
diff --git a/arch/avr/src/at32uc3/at32uc3_clkinit.c b/arch/avr/src/at32uc3/at32uc3_clkinit.c
index db62c3436c..c15dc627e1 100644
--- a/arch/avr/src/at32uc3/at32uc3_clkinit.c
+++ b/arch/avr/src/at32uc3/at32uc3_clkinit.c
@@ -27,7 +27,7 @@
 #include <arch/board/board.h>
 
 #include "at32uc3_config.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 #include "at32uc3_pm.h"
 #include "at32uc3_flashc.h"
diff --git a/arch/avr/src/at32uc3/at32uc3_gpio.c b/arch/avr/src/at32uc3/at32uc3_gpio.c
index 7eaed32fe8..79bdca4d58 100644
--- a/arch/avr/src/at32uc3/at32uc3_gpio.c
+++ b/arch/avr/src/at32uc3/at32uc3_gpio.c
@@ -28,7 +28,7 @@
 #include <assert.h>
 
 #include "at32uc3_config.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 
 #include "chip.h"
diff --git a/arch/avr/src/at32uc3/at32uc3_gpioirq.c b/arch/avr/src/at32uc3/at32uc3_gpioirq.c
index 0fcdb3a620..207ab7fc61 100644
--- a/arch/avr/src/at32uc3/at32uc3_gpioirq.c
+++ b/arch/avr/src/at32uc3/at32uc3_gpioirq.c
@@ -33,7 +33,7 @@
 
 #include <nuttx/irq.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "irq/irq.h"
 #include "at32uc3.h"
 #include "at32uc3_gpio.h"
diff --git a/arch/avr/src/at32uc3/at32uc3_irq.c b/arch/avr/src/at32uc3/at32uc3_irq.c
index 76dbde5d8c..f68954163c 100644
--- a/arch/avr/src/at32uc3/at32uc3_irq.c
+++ b/arch/avr/src/at32uc3/at32uc3_irq.c
@@ -34,7 +34,7 @@
 #include <nuttx/arch.h>
 #include <arch/irq.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 
 #include "chip.h"
diff --git a/arch/avr/src/at32uc3/at32uc3_lowconsole.c b/arch/avr/src/at32uc3/at32uc3_lowconsole.c
index b7fbf50d43..f8d2474871 100644
--- a/arch/avr/src/at32uc3/at32uc3_lowconsole.c
+++ b/arch/avr/src/at32uc3/at32uc3_lowconsole.c
@@ -31,7 +31,7 @@
 #include <nuttx/irq.h>
 #include <arch/board/board.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 #include "at32uc3_pm.h"
 #include "at32uc3_usart.h"
@@ -356,7 +356,7 @@ void up_consoleinit(void)
   putreg32(regval, AVR32_PM_PBAMASK);
 
   /* Then configure the console here (if it is not going to be configured
-   * by up_earlyserialinit()).
+   * by avr_earlyserialinit()).
    */
 
 #if defined(HAVE_SERIAL_CONSOLE) && !defined(USE_EARLYSERIALINIT)
@@ -367,14 +367,14 @@ void up_consoleinit(void)
 }
 
 /****************************************************************************
- * Name: up_lowputc
+ * Name: avr_lowputc
  *
  * Description:
  *   Output one byte on the serial console
  *
  ****************************************************************************/
 
-void up_lowputc(char ch)
+void avr_lowputc(char ch)
 {
 #ifdef HAVE_SERIAL_CONSOLE
   /* Wait until the TX to become ready */
diff --git a/arch/avr/src/at32uc3/at32uc3_lowinit.c b/arch/avr/src/at32uc3/at32uc3_lowinit.c
index 4fbef8922a..75fa4daf3b 100644
--- a/arch/avr/src/at32uc3/at32uc3_lowinit.c
+++ b/arch/avr/src/at32uc3/at32uc3_lowinit.c
@@ -25,7 +25,7 @@
 #include <nuttx/config.h>
 
 #include "at32uc3_config.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 
 /****************************************************************************
@@ -57,7 +57,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: up_lowinit
+ * Name: avr_lowinit
  *
  * Description:
  *   This performs basic initialization of the USART used for the serial
@@ -66,7 +66,7 @@
  *
  ****************************************************************************/
 
-void up_lowinit(void)
+void avr_lowinit(void)
 {
   /* Initialize MCU clocking */
 
@@ -81,7 +81,7 @@ void up_lowinit(void)
    */
 
 #ifdef USE_EARLYSERIALINIT
-  up_earlyserialinit();
+  avr_earlyserialinit();
 #endif
 
   /* Perform board-level initialization */
diff --git a/arch/avr/src/at32uc3/at32uc3_serial.c b/arch/avr/src/at32uc3/at32uc3_serial.c
index cf0007ff13..c6a2141f01 100644
--- a/arch/avr/src/at32uc3/at32uc3_serial.c
+++ b/arch/avr/src/at32uc3/at32uc3_serial.c
@@ -42,7 +42,7 @@
 #include "at32uc3_config.h"
 #include "chip.h"
 #include "at32uc3_usart.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at32uc3.h"
 
 /****************************************************************************
@@ -687,18 +687,18 @@ static bool up_txready(struct uart_dev_s *dev)
 #ifdef USE_EARLYSERIALINIT
 
 /****************************************************************************
- * Name: up_earlyserialinit
+ * Name: avr_earlyserialinit
  *
  * Description:
  *   Performs the low level USART initialization early in debug so that the
  *   serial console will be available during bootup.  This must be called
- *   before up_serialinit.  NOTE:  This function depends on GPIO pin
+ *   before avr_serialinit.  NOTE:  This function depends on GPIO pin
  *   configuration performed in up_consoleinit() and main clock
  *   initialization performed in up_clkinitialize().
  *
  ****************************************************************************/
 
-void up_earlyserialinit(void)
+void avr_earlyserialinit(void)
 {
   /* Disable all USARTS */
 
@@ -720,15 +720,15 @@ void up_earlyserialinit(void)
 #endif
 
 /****************************************************************************
- * Name: up_serialinit
+ * Name: avr_serialinit
  *
  * Description:
  *   Register serial console and serial ports.  This assumes
- *   that up_earlyserialinit was called previously.
+ *   that avr_earlyserialinit was called previously.
  *
  ****************************************************************************/
 
-void up_serialinit(void)
+void avr_serialinit(void)
 {
   /* Register the console */
 
@@ -769,10 +769,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
   up_restoreusartint(priv, imr);
 #endif
   return ch;
@@ -797,10 +797,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
 #endif
   return ch;
 }
diff --git a/arch/avr/src/at32uc3/at32uc3_timerisr.c b/arch/avr/src/at32uc3/at32uc3_timerisr.c
index f08c9fb83d..e6844a248c 100644
--- a/arch/avr/src/at32uc3/at32uc3_timerisr.c
+++ b/arch/avr/src/at32uc3/at32uc3_timerisr.c
@@ -29,7 +29,7 @@
 #include <nuttx/arch.h>
 #include <arch/board/board.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "chip.h"
 #include "at32uc3.h"
 #include "at32uc3_pm.h"
diff --git a/arch/avr/src/at90usb/Make.defs b/arch/avr/src/at90usb/Make.defs
index 31ae54b553..5045f3bb33 100644
--- a/arch/avr/src/at90usb/Make.defs
+++ b/arch/avr/src/at90usb/Make.defs
@@ -24,31 +24,31 @@ HEAD_ASRC = at90usb_head.S
 
 # Common AVR files
 
-CMN_ASRCS  = up_switchcontext.S
-CMN_CSRCS  = up_allocateheap.c up_assert.c up_blocktask.c up_copystate.c
-CMN_CSRCS += up_createstack.c up_doirq.c up_exit.c  up_idle.c up_initialize.c
-CMN_CSRCS += up_initialstate.c up_irq.c up_lowputs.c
-CMN_CSRCS += up_mdelay.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c
-CMN_CSRCS += up_nputs.c up_releasepending.c up_releasestack.c
-CMN_CSRCS += up_schedulesigaction.c up_sigdeliver.c
-CMN_CSRCS += up_stackframe.c up_udelay.c up_unblocktask.c up_usestack.c
+CMN_ASRCS  = avr_switchcontext.S
+CMN_CSRCS  = avr_allocateheap.c avr_assert.c avr_blocktask.c avr_copystate.c
+CMN_CSRCS += avr_createstack.c avr_doirq.c avr_exit.c  avr_idle.c avr_initialize.c
+CMN_CSRCS += avr_initialstate.c avr_irq.c avr_lowputs.c
+CMN_CSRCS += avr_mdelay.c avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c
+CMN_CSRCS += avr_nputs.c avr_releasepending.c avr_releasestack.c
+CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c
+CMN_CSRCS += avr_stackframe.c avr_udelay.c avr_unblocktask.c avr_usestack.c
 
 # Configuration-dependent common files
 
 ifeq ($(CONFIG_ARCH_STACKDUMP),y)
-CMN_CSRCS += up_dumpstate.c
+CMN_CSRCS += avr_dumpstate.c
 endif
 
 ifeq ($(CONFIG_AVR_SPI),y)
-CMN_CSRCS += up_spi.c
+CMN_CSRCS += avr_spi.c
 endif
 
 ifeq ($(CONFIG_STACK_COLORATION),y)
-CMN_CSRCS += up_checkstack.c
+CMN_CSRCS += avr_checkstack.c
 endif
 
 ifeq ($(CONFIG_ARCH_ROMGETC),y)
-CMN_CSRCS += up_romgetc.c
+CMN_CSRCS += avr_romgetc.c
 endif
 
 # Required AT90USB files
diff --git a/arch/avr/src/at90usb/at90usb_exceptions.S b/arch/avr/src/at90usb/at90usb_exceptions.S
index 89a86fd564..adef3a52c8 100644
--- a/arch/avr/src/at90usb/at90usb_exceptions.S
+++ b/arch/avr/src/at90usb/at90usb_exceptions.S
@@ -37,8 +37,8 @@
  ********************************************************************************************/
 
 	.file	"at90usb_exceptions.S"
-	.global	up_doirq
-	.global	up_fullcontextrestore
+	.global	avr_doirq
+	.global	avr_fullcontextrestore
 
 /********************************************************************************************
  * Macros
@@ -109,7 +109,7 @@ excpt_common:
 
 	EXCPT_PROLOGUE
 
-	/* Call up_doirq with r24 = IRQ number, r22-23 = Pointer to the save structure.  The stack
+	/* Call avr_doirq with r24 = IRQ number, r22-23 = Pointer to the save structure.  The stack
 	 * pointer currently points to the save structure (or maybe the save structure -1 since
 	 * the push operation post-decrements -- need to REVISIT this).
 	 */
@@ -119,7 +119,7 @@ excpt_common:
 	adiw	r28, 1					/* Remembering that push post-decrements */
 	movw	r22, r28				/* Pass register save structure as the parameter 2 */
 	USE_INTSTACK rx, ry, rz			/* Switch to the interrupt stack */
-	call	up_doirq				/* Dispatch the interrupt */
+	call	avr_doirq				/* Dispatch the interrupt */
 	RESTORE_STACK rx, ry			/* Undo the operations of USE_INTSTACK */
 
 	/* up_doiq returns with r24-r25 equal to the new save structure.  If no context
@@ -132,11 +132,11 @@ excpt_common:
 	 cpc	r29, r25
 	 breq	.Lnoswitch
 
-	/* A context switch has occurred, jump to up_fullcontextrestore with r24, r25
+	/* A context switch has occurred, jump to avr_fullcontextrestore with r24, r25
 	 * equal to the address of the new register save area.
 	 */
 
-	jmp	up_fullcontextrestore
+	jmp	avr_fullcontextrestore
 
 	/* No context switch occurred.. just return off the stack */
 
diff --git a/arch/avr/src/at90usb/at90usb_head.S b/arch/avr/src/at90usb/at90usb_head.S
index c87a3ac209..8f93c17177 100644
--- a/arch/avr/src/at90usb/at90usb_head.S
+++ b/arch/avr/src/at90usb/at90usb_head.S
@@ -58,7 +58,7 @@
 	.global	_edata				/* End of .data section in RAM */
 	.global	_eronly				/* Start of .data section in FLASH */
 	.global	_enoinit			/* End of uninitialized data.  Defined by ld.script */
-	.global	up_lowinit			/* Perform low level initialization */
+	.global	avr_lowinit			/* Perform low level initialization */
 	.global	nx_start			/* NuttX entry point */
 
 	.global	vectortab
@@ -239,7 +239,7 @@ __do_clear_bss:
 
 	/* Perform any low-level initialization */
 
-	call	up_lowinit
+	call	avr_lowinit
 
 	/* Now start NuttX */
 
diff --git a/arch/avr/src/at90usb/at90usb_lowconsole.c b/arch/avr/src/at90usb/at90usb_lowconsole.c
index d896f4e3c7..e5a3fe73bd 100644
--- a/arch/avr/src/at90usb/at90usb_lowconsole.c
+++ b/arch/avr/src/at90usb/at90usb_lowconsole.c
@@ -32,7 +32,7 @@
 #include <arch/board/board.h>
 #include <avr/io.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at90usb.h"
 
 /****************************************************************************
@@ -251,14 +251,14 @@ void up_consoleinit(void)
 }
 
 /****************************************************************************
- * Name: up_lowputc
+ * Name: avr_lowputc
  *
  * Description:
  *   Output one byte on the serial console
  *
  ****************************************************************************/
 
-void up_lowputc(char ch)
+void avr_lowputc(char ch)
 {
 #ifdef HAVE_SERIAL_CONSOLE
   while ((UCSR1A & (1 << UDRE1)) == 0);
diff --git a/arch/avr/src/at90usb/at90usb_lowinit.c b/arch/avr/src/at90usb/at90usb_lowinit.c
index d4031fe355..33ba00dc79 100644
--- a/arch/avr/src/at90usb/at90usb_lowinit.c
+++ b/arch/avr/src/at90usb/at90usb_lowinit.c
@@ -27,7 +27,7 @@
 #include <avr/power.h>
 
 #include "at90usb_config.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at90usb.h"
 
 /****************************************************************************
@@ -96,7 +96,7 @@ static inline void up_wdtinit(void)
  ****************************************************************************/
 
 /****************************************************************************
- * Name: up_lowinit
+ * Name: avr_lowinit
  *
  * Description:
  *   This performs basic initialization of the USART used for the serial
@@ -105,7 +105,7 @@ static inline void up_wdtinit(void)
  *
  ****************************************************************************/
 
-void up_lowinit(void)
+void avr_lowinit(void)
 {
   /* Disable the watchdog timer */
 
@@ -128,7 +128,7 @@ void up_lowinit(void)
    */
 
 #ifdef USE_EARLYSERIALINIT
-  up_earlyserialinit();
+  avr_earlyserialinit();
 #endif
 
   /* Perform board-level initialization */
diff --git a/arch/avr/src/at90usb/at90usb_serial.c b/arch/avr/src/at90usb/at90usb_serial.c
index 44b353297b..3518bf35f1 100644
--- a/arch/avr/src/at90usb/at90usb_serial.c
+++ b/arch/avr/src/at90usb/at90usb_serial.c
@@ -40,7 +40,7 @@
 
 #include <arch/board/board.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at90usb.h"
 
 /****************************************************************************
@@ -507,16 +507,16 @@ static bool usart1_txempty(struct uart_dev_s *dev)
 #ifdef USE_EARLYSERIALINIT
 
 /****************************************************************************
- * Name: up_earlyserialinit
+ * Name: avr_earlyserialinit
  *
  * Description:
  *   Performs the low level USART initialization early in debug so that the
  *   serial console will be available during bootup.  This must be called
- *   before up_serialinit.
+ *   before avr_serialinit.
  *
  ****************************************************************************/
 
-void up_earlyserialinit(void)
+void avr_earlyserialinit(void)
 {
   /* Disable all USARTS */
 
@@ -532,15 +532,15 @@ void up_earlyserialinit(void)
 #endif
 
 /****************************************************************************
- * Name: up_serialinit
+ * Name: avr_serialinit
  *
  * Description:
  *   Register serial console and serial ports.  This assumes
- *   that up_earlyserialinit was called previously.
+ *   that avr_earlyserialinit was called previously.
  *
  ****************************************************************************/
 
-void up_serialinit(void)
+void avr_serialinit(void)
 {
   /* Register the console */
 
@@ -574,10 +574,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
   usart1_restoreusartint(imr);
 #endif
   return ch;
@@ -602,10 +602,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
 #endif
   return ch;
 }
diff --git a/arch/avr/src/at90usb/at90usb_timerisr.c b/arch/avr/src/at90usb/at90usb_timerisr.c
index 5859d4c17e..b92d931fbe 100644
--- a/arch/avr/src/at90usb/at90usb_timerisr.c
+++ b/arch/avr/src/at90usb/at90usb_timerisr.c
@@ -32,7 +32,7 @@
 #include <arch/board/board.h>
 #include <avr/io.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "at90usb.h"
 
 /****************************************************************************
diff --git a/arch/avr/src/at90usb/at90usb_usbdev.c b/arch/avr/src/at90usb/at90usb_usbdev.c
index 42239889c5..1f9f734947 100644
--- a/arch/avr/src/at90usb/at90usb_usbdev.c
+++ b/arch/avr/src/at90usb/at90usb_usbdev.c
@@ -46,7 +46,7 @@
 #include <arch/board/board.h>
 
 #include "chip.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -2801,7 +2801,7 @@ static int avr_pullup(struct usbdev_s *dev, bool enable)
  ****************************************************************************/
 
 /****************************************************************************
- * Name: up_usbinitialize
+ * Name: avr_usbinitialize
  *
  * Description:
  *   Initialize USB hardware.
@@ -2815,7 +2815,7 @@ static int avr_pullup(struct usbdev_s *dev, bool enable)
  *
  ****************************************************************************/
 
-void up_usbinitialize(void)
+void avr_usbinitialize(void)
 {
   usbtrace(TRACE_DEVINIT, 0);
 
@@ -2868,14 +2868,14 @@ void up_usbinitialize(void)
   return;
 
 errout:
-  up_usbuninitialize();
+  avr_usbuninitialize();
 }
 
 /****************************************************************************
- * Name: up_usbuninitialize
+ * Name: avr_usbuninitialize
  ****************************************************************************/
 
-void up_usbuninitialize(void)
+void avr_usbuninitialize(void)
 {
   irqstate_t flags;
 
diff --git a/arch/avr/src/atmega/Make.defs b/arch/avr/src/atmega/Make.defs
index 5e43e2c028..35890bf7e4 100644
--- a/arch/avr/src/atmega/Make.defs
+++ b/arch/avr/src/atmega/Make.defs
@@ -24,31 +24,31 @@ HEAD_ASRC = atmega_head.S
 
 # Common AVR files
 
-CMN_ASRCS  = up_switchcontext.S
-CMN_CSRCS  = up_allocateheap.c up_assert.c up_blocktask.c up_copystate.c
-CMN_CSRCS += up_createstack.c up_doirq.c up_exit.c  up_idle.c up_initialize.c
-CMN_CSRCS += up_initialstate.c up_irq.c up_lowputs.c
-CMN_CSRCS += up_mdelay.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c
-CMN_CSRCS += up_nputs.c up_releasepending.c up_releasestack.c
-CMN_CSRCS += up_schedulesigaction.c up_sigdeliver.c
-CMN_CSRCS += up_stackframe.c up_udelay.c up_unblocktask.c up_usestack.c
+CMN_ASRCS  = avr_switchcontext.S
+CMN_CSRCS  = avr_allocateheap.c avr_assert.c avr_blocktask.c avr_copystate.c
+CMN_CSRCS += avr_createstack.c avr_doirq.c avr_exit.c  avr_idle.c avr_initialize.c
+CMN_CSRCS += avr_initialstate.c avr_irq.c avr_lowputs.c
+CMN_CSRCS += avr_mdelay.c avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c
+CMN_CSRCS += avr_nputs.c avr_releasepending.c avr_releasestack.c
+CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c
+CMN_CSRCS += avr_stackframe.c avr_udelay.c avr_unblocktask.c avr_usestack.c
 
 # Configuration-dependent common files
 
 ifeq ($(CONFIG_ARCH_STACKDUMP),y)
-CMN_CSRCS += up_dumpstate.c
+CMN_CSRCS += avr_dumpstate.c
 endif
 
 ifeq ($(CONFIG_AVR_SPI),y)
-CMN_CSRCS += up_spi.c
+CMN_CSRCS += avr_spi.c
 endif
 
 ifeq ($(CONFIG_STACK_COLORATION),y)
-CMN_CSRCS += up_checkstack.c
+CMN_CSRCS += avr_checkstack.c
 endif
 
 ifeq ($(CONFIG_ARCH_ROMGETC),y)
-CMN_CSRCS += up_romgetc.c
+CMN_CSRCS += avr_romgetc.c
 endif
 
 # Required ATMEGA files
diff --git a/arch/avr/src/atmega/atmega_exceptions.S b/arch/avr/src/atmega/atmega_exceptions.S
index faa9e5e7c9..514c61870f 100644
--- a/arch/avr/src/atmega/atmega_exceptions.S
+++ b/arch/avr/src/atmega/atmega_exceptions.S
@@ -33,8 +33,8 @@
  ********************************************************************************************/
 
 	.file	"atmega_exceptions.S"
-	.global	up_doirq
-	.global	up_fullcontextrestore
+	.global	avr_doirq
+	.global	avr_fullcontextrestore
 
 /********************************************************************************************
  * Macros
@@ -198,7 +198,7 @@ excpt_common:
 
 	EXCPT_PROLOGUE
 
-	/* Call up_doirq with r24 = IRQ number, r22-23 = Pointer to the save structure.  The stack
+	/* Call avr_doirq with r24 = IRQ number, r22-23 = Pointer to the save structure.  The stack
 	 * pointer currently points to the save structure (or maybe the save structure -1 since
 	 * the push operation post-decrements -- need to REVISIT this).
 	 */
@@ -208,7 +208,7 @@ excpt_common:
 	adiw	r28, 1					/* Remembering that push post-decrements */
 	movw	r22, r28				/* Pass register save structure as the parameter 2 */
 	USE_INTSTACK rx, ry, rz			/* Switch to the interrupt stack */
-	call	up_doirq				/* Dispatch the interrupt */
+	call	avr_doirq				/* Dispatch the interrupt */
 	RESTORE_STACK rx, ry			/* Undo the operations of USE_INTSTACK */
 
 	/* up_doiq returns with r24-r25 equal to the new save structure.  If no context
@@ -221,11 +221,11 @@ excpt_common:
 	 cpc	r29, r25
 	 breq	.Lnoswitch
 
-	/* A context switch has occurred, jump to up_fullcontextrestore with r24, r25
+	/* A context switch has occurred, jump to avr_fullcontextrestore with r24, r25
 	 * equal to the address of the new register save ared.
 	 */
 
-	jmp	up_fullcontextrestore
+	jmp	avr_fullcontextrestore
 
 	/* No context switch occurred.. just return off the stack */
 
diff --git a/arch/avr/src/atmega/atmega_head.S b/arch/avr/src/atmega/atmega_head.S
index d9afcdb2ce..9ab077557a 100644
--- a/arch/avr/src/atmega/atmega_head.S
+++ b/arch/avr/src/atmega/atmega_head.S
@@ -60,7 +60,7 @@
 	.global	_edata				/* End of .data section in RAM */
 	.global	_eronly				/* Start of .data section in FLASH */
 	.global	_enoinit			/* End of uninitilized data.  Defined by ld.script */
-	.global	up_lowinit			/* Perform low level initialization */
+	.global	avr_lowinit			/* Perform low level initialization */
 	.global	nx_start			/* NuttX entry point */
 
 	.global	vectortab
@@ -435,7 +435,7 @@ __do_clear_bss:
 
 	/* Perform any low-level initialization */
 
-	call	up_lowinit
+	call	avr_lowinit
 
 	/* Now start NuttX */
 
diff --git a/arch/avr/src/atmega/atmega_lowconsole.c b/arch/avr/src/atmega/atmega_lowconsole.c
index 36c7edc33a..8c024d4ee0 100644
--- a/arch/avr/src/atmega/atmega_lowconsole.c
+++ b/arch/avr/src/atmega/atmega_lowconsole.c
@@ -32,7 +32,7 @@
 #include <arch/board/board.h>
 #include <avr/io.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "atmega.h"
 
 /****************************************************************************
@@ -442,14 +442,14 @@ void up_consoleinit(void)
 }
 
 /****************************************************************************
- * Name: up_lowputc
+ * Name: avr_lowputc
  *
  * Description:
  *   Output one byte on the serial console
  *
  ****************************************************************************/
 
-void up_lowputc(char ch)
+void avr_lowputc(char ch)
 {
 #ifdef HAVE_SERIAL_CONSOLE
 #  if defined(CONFIG_USART0_SERIAL_CONSOLE)
diff --git a/arch/avr/src/atmega/atmega_lowinit.c b/arch/avr/src/atmega/atmega_lowinit.c
index 8be8881b85..477954535b 100644
--- a/arch/avr/src/atmega/atmega_lowinit.c
+++ b/arch/avr/src/atmega/atmega_lowinit.c
@@ -27,7 +27,7 @@
 #include <avr/power.h>
 
 #include "atmega_config.h"
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "atmega.h"
 
 /****************************************************************************
@@ -96,7 +96,7 @@ static inline void up_wdtinit(void)
  ****************************************************************************/
 
 /****************************************************************************
- * Name: up_lowinit
+ * Name: avr_lowinit
  *
  * Description:
  *   This performs basic initialization of the USART used for the serial
@@ -105,7 +105,7 @@ static inline void up_wdtinit(void)
  *
  ****************************************************************************/
 
-void up_lowinit(void)
+void avr_lowinit(void)
 {
   /* Disable the watchdog timer */
 
@@ -133,7 +133,7 @@ void up_lowinit(void)
    */
 
 #ifdef USE_EARLYSERIALINIT
-  up_earlyserialinit();
+  avr_earlyserialinit();
 #endif
 
   /* Perform board-level initialization */
diff --git a/arch/avr/src/atmega/atmega_serial.c b/arch/avr/src/atmega/atmega_serial.c
index 94ff3dc955..8525de510d 100644
--- a/arch/avr/src/atmega/atmega_serial.c
+++ b/arch/avr/src/atmega/atmega_serial.c
@@ -40,7 +40,7 @@
 
 #include <arch/board/board.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "atmega.h"
 
 /****************************************************************************
@@ -823,16 +823,16 @@ static bool usart1_txempty(struct uart_dev_s *dev)
 #ifdef USE_EARLYSERIALINIT
 
 /****************************************************************************
- * Name: up_earlyserialinit
+ * Name: avr_earlyserialinit
  *
  * Description:
  *   Performs the low level USART initialization early in debug so that the
  *   serial console will be available during bootup.  This must be called
- *   before up_serialinit.
+ *   before avr_serialinit.
  *
  ****************************************************************************/
 
-void up_earlyserialinit(void)
+void avr_earlyserialinit(void)
 {
   /* Disable all USARTS */
 
@@ -857,15 +857,15 @@ void up_earlyserialinit(void)
 #endif
 
 /****************************************************************************
- * Name: up_serialinit
+ * Name: avr_serialinit
  *
  * Description:
  *   Register serial console and serial ports.  This assumes
- *   that up_earlyserialinit was called previously.
+ *   that avr_earlyserialinit was called previously.
  *
  ****************************************************************************/
 
-void up_serialinit(void)
+void avr_serialinit(void)
 {
   /* Register the console */
 
@@ -906,10 +906,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
 
 #if defined(CONFIG_USART0_SERIAL_CONSOLE)
   usart0_restoreusartint(imr);
@@ -940,10 +940,10 @@ int up_putc(int ch)
     {
       /* Add CR */
 
-      up_lowputc('\r');
+      avr_lowputc('\r');
     }
 
-  up_lowputc(ch);
+  avr_lowputc(ch);
 #endif
   return ch;
 }
diff --git a/arch/avr/src/atmega/atmega_timerisr.c b/arch/avr/src/atmega/atmega_timerisr.c
index bc7e4f58b6..2c082d5eba 100644
--- a/arch/avr/src/atmega/atmega_timerisr.c
+++ b/arch/avr/src/atmega/atmega_timerisr.c
@@ -32,7 +32,7 @@
 #include <arch/board/board.h>
 #include <avr/io.h>
 
-#include "up_internal.h"
+#include "avr_internal.h"
 #include "atmega.h"
 
 /****************************************************************************
diff --git a/arch/avr/src/avr/avr.h b/arch/avr/src/avr/avr.h
index 32cfb6ca49..28ee9de3d5 100644
--- a/arch/avr/src/avr/avr.h
+++ b/arch/avr/src/avr/avr.h
@@ -43,8 +43,8 @@
  * state from the TCB.
  */
 
-#define up_savestate(regs)    up_copystate(regs, (uint8_t*)g_current_regs)
-#define up_restorestate(regs) (g_current_regs = regs)
+#define avr_savestate(regs)    avr_copystate(regs, (uint8_t*)g_current_regs)
+#define avr_restorestate(regs) (g_current_regs = regs)
 
 /****************************************************************************
  * Public Types
@@ -77,7 +77,7 @@ extern uint16_t g_idle_topstack;
 struct spi_dev_s; /* Forward references */
 
 /****************************************************************************
- * Name:  up_copystate
+ * Name:  avr_copystate
  *
  * Description:
  *   Copy the contents of a register state save structure from one location
@@ -85,37 +85,37 @@ struct spi_dev_s; /* Forward references */
  *
  ****************************************************************************/
 
-void up_copystate(uint8_t *dest, uint8_t *src);
+void avr_copystate(uint8_t *dest, uint8_t *src);
 
 /****************************************************************************
- * Name:  up_fullcontextrestore
+ * Name:  avr_fullcontextrestore
  *
  * Description:
  *   Restore the full context of a saved thread/task.
  *
  ****************************************************************************/
 
-void up_fullcontextrestore(uint8_t *restoreregs) noreturn_function;
+void avr_fullcontextrestore(uint8_t *restoreregs) noreturn_function;
 
 /****************************************************************************
- * Name:  up_switchcontext
+ * Name:  avr_switchcontext
  *
  * Description:
  *   Switch from one thread/task context to another.
  *
  ****************************************************************************/
 
-void up_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
+void avr_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
 
 /****************************************************************************
- * Name:  up_doirq
+ * Name:  avr_doirq
  *
  * Description:
  *   Dispatch an interrupt.
  *
  ****************************************************************************/
 
-uint8_t *up_doirq(uint8_t irq, uint8_t *regs);
+uint8_t *avr_doirq(uint8_t irq, uint8_t *regs);
 
 /****************************************************************************
  * Name: avr_spibus_initialize
diff --git a/arch/avr/src/avr/avr_blocktask.c b/arch/avr/src/avr/avr_blocktask.c
new file mode 100644
index 0000000000..344b271ac8
--- /dev/null
+++ b/arch/avr/src/avr/avr_blocktask.c
@@ -0,0 +1,109 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_blocktask.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_block_task
+ *
+ * Description:
+ *   The currently executing task has already removed from ready-to-run list.
+ *   Save its context and switch to the next running task at the head of the
+ *   ready-to-run list.
+ *
+ * Input Parameters:
+ *   rtcb: Reference to the running task which is different to the
+ *     task (next running task) at the head of the list.
+ *
+ ****************************************************************************/
+
+void up_block_task(struct tcb_s *rtcb)
+{
+  /* Update scheduler parameters */
+
+  nxsched_suspend_scheduler(rtcb);
+
+  /* Are we in an interrupt handler? */
+
+  if (g_current_regs)
+    {
+      /* Yes, then we have to do things differently.
+       * Just copy the g_current_regs into the OLD rtcb.
+       */
+
+      avr_savestate(rtcb->xcp.regs);
+
+      /* Restore the exception context of the rtcb at the (new) head
+       * of the ready-to-run task list.
+       */
+
+      rtcb = this_task();
+
+      /* Reset scheduler parameters */
+
+      nxsched_resume_scheduler(rtcb);
+
+      /* Then switch contexts */
+
+      avr_restorestate(rtcb->xcp.regs);
+    }
+
+  /* No, then we will need to perform the user context switch */
+
+  else
+    {
+      struct tcb_s *nexttcb = this_task();
+
+      /* Reset scheduler parameters */
+
+      nxsched_resume_scheduler(nexttcb);
+
+      /* Switch context to the context of the task at the head of the
+       * ready to run list.
+       */
+
+      avr_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
+
+      /* avr_switchcontext forces a context switch to the task at the
+       * head of the ready-to-run list.  It does not 'return' in the
+       * normal sense.  When it does return, it is because the blocked
+       * task is again ready to run and has execution priority.
+       */
+    }
+}
diff --git a/arch/avr/src/avr/avr_checkstack.c b/arch/avr/src/avr/avr_checkstack.c
new file mode 100644
index 0000000000..d7e54d68a7
--- /dev/null
+++ b/arch/avr/src/avr/avr_checkstack.c
@@ -0,0 +1,179 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_checkstack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+
+#include "avr_internal.h"
+#include "sched/sched.h"
+
+#ifdef CONFIG_STACK_COLORATION
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_stack_check
+ *
+ * Description:
+ *   Determine (approximately) how much stack has been used be searching the
+ *   stack memory for a high water mark.  That is, the deepest level of the
+ *   stack that clobbered some recognizable marker in the stack memory.
+ *
+ * Input Parameters:
+ *   alloc - Allocation base address of the stack
+ *   size - The size of the stack in bytes
+ *
+ * Returned Value:
+ *   The estimated amount of stack space used.
+ *
+ ****************************************************************************/
+
+size_t avr_stack_check(uintptr_t alloc, size_t size)
+{
+  FAR uint8_t *ptr;
+  size_t mark;
+#if 0
+  int i;
+  int j;
+#endif
+
+  /* The AVR uses a push-down stack:  the stack grows toward lower addresses
+   * in memory.  We need to start at the lowest address in the stack memory
+   * allocation and search to higher addresses.  The first byte we encounter
+   * that does not have the magic value is the high water mark.
+   */
+
+  for (ptr = (FAR uint8_t *)alloc, mark = size;
+       *ptr == STACK_COLOR && mark > 0;
+       ptr++, mark--);
+
+  /* If the stack is completely used, then this might mean that the stack
+   * overflowed from above (meaning that the stack is too small), or may
+   * have been overwritten from below meaning that some other stack or data
+   * structure overflowed.
+   *
+   * If you see returned values saying that the entire stack is being used
+   * then enable the following logic to see it there are unused areas in the
+   * middle of the stack.
+   */
+
+#if 0
+  if (mark + 16 > size)
+    {
+      ptr = (FAR uint8_t *)alloc;
+      for (i = 0; i < size; i += 64)
+        {
+          for (j = 0; j < 64; j++)
+            {
+              int ch;
+              if (*ptr++ == STACK_COLOR)
+                {
+                  ch = '.';
+                }
+              else
+                {
+                  ch = 'X';
+                }
+
+              up_putc(ch);
+            }
+
+          up_putc('\n');
+        }
+    }
+#endif
+
+  /* Return our guess about how much stack space was used */
+
+  return mark;
+}
+
+/****************************************************************************
+ * Name: up_check_stack and friends
+ *
+ * Description:
+ *   Determine (approximately) how much stack has been used be searching the
+ *   stack memory for a high water mark.  That is, the deepest level of the
+ *   stack that clobbered some recognizable marker in the stack memory.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   The estimated amount of stack space used.
+ *
+ ****************************************************************************/
+
+size_t up_check_tcbstack(FAR struct tcb_s *tcb)
+{
+  return avr_stack_check((uintptr_t)tcb->stack_base_ptr,
+                         tcb->adj_stack_size);
+}
+
+ssize_t up_check_tcbstack_remain(FAR struct tcb_s *tcb)
+{
+  return tcb->adj_stack_size - up_check_tcbstack(tcb);
+}
+
+size_t up_check_stack(void)
+{
+  return up_check_tcbstack(running_task());
+}
+
+ssize_t up_check_stack_remain(void)
+{
+  return up_check_tcbstack_remain(running_task());
+}
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+size_t up_check_intstack(void)
+{
+  uintptr_t start = (uintptr_t)g_intstackalloc;
+  return avr_stack_check(start, CONFIG_ARCH_INTERRUPTSTACK & ~3);
+}
+
+size_t up_check_intstack_remain(void)
+{
+  return (CONFIG_ARCH_INTERRUPTSTACK & ~3) - up_check_intstack();
+}
+#endif
+
+#endif /* CONFIG_STACK_COLORATION */
diff --git a/arch/avr/src/avr/avr_copystate.c b/arch/avr/src/avr/avr_copystate.c
new file mode 100644
index 0000000000..1c44e51727
--- /dev/null
+++ b/arch/avr/src/avr/avr_copystate.c
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_copystate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <arch/irq.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_copystate
+ ****************************************************************************/
+
+/* Really just a memcpy */
+
+void avr_copystate(uint8_t *dest, uint8_t *src)
+{
+  int i;
+
+  /* The state is copied from the stack to the TCB, but only a reference is
+   * passed to get the state from the TCB.  So the following check avoids
+   * copying the TCB save area onto itself:
+   */
+
+  if (src != dest)
+    {
+      for (i = 0; i < XCPTCONTEXT_REGS; i++)
+        {
+          *dest++ = *src++;
+        }
+    }
+}
diff --git a/arch/avr/src/avr/avr_createstack.c b/arch/avr/src/avr/avr_createstack.c
new file mode 100644
index 0000000000..a1d158829a
--- /dev/null
+++ b/arch/avr/src/avr/avr_createstack.c
@@ -0,0 +1,191 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_createstack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+#include <arch/board/board.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ *   Allocate a stack for a new thread and setup up stack-related information
+ *   in the TCB.
+ *
+ *   The following TCB fields must be initialized by this function:
+ *
+ *   - adj_stack_size: Stack size after adjustment for hardware, processor,
+ *     etc.  This value is retained only for debug purposes.
+ *   - stack_alloc_ptr: Pointer to allocated stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb: The TCB of new task
+ *   - stack_size:  The requested stack size.  At least this much
+ *     must be allocated.
+ *   - ttype:  The thread type.  This may be one of following (defined in
+ *     include/nuttx/sched.h):
+ *
+ *       TCB_FLAG_TTYPE_TASK     Normal user task
+ *       TCB_FLAG_TTYPE_PTHREAD  User pthread
+ *       TCB_FLAG_TTYPE_KERNEL   Kernel thread
+ *
+ *     This thread type is normally available in the flags field of the TCB,
+ *     however, there are certain contexts where the TCB may not be fully
+ *     initialized when up_create_stack is called.
+ *
+ ****************************************************************************/
+
+int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
+{
+#ifdef CONFIG_TLS_ALIGNED
+  /* The allocated stack size must not exceed the maximum possible for the
+   * TLS feature.
+   */
+
+  DEBUGASSERT(stack_size <= TLS_MAXSTACK);
+  if (stack_size >= TLS_MAXSTACK)
+    {
+      stack_size = TLS_MAXSTACK;
+    }
+#endif
+
+  /* Is there already a stack allocated of a different size?  Because of
+   * alignment issues, stack_size might erroneously appear to be of a
+   * different size.  Fortunately, this is not a critical operation.
+   */
+
+  if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
+    {
+      /* Yes.. Release the old stack */
+
+      up_release_stack(tcb, ttype);
+    }
+
+  /* Do we need to allocate a new stack? */
+
+  if (!tcb->stack_alloc_ptr)
+    {
+      /* Allocate the stack.  If DEBUG is enabled (but not stack debug),
+       * then create a zeroed stack to make stack dumps easier to trace.
+       * If TLS is enabled, then we must allocate aligned stacks.
+       */
+
+#ifdef CONFIG_TLS_ALIGNED
+#ifdef CONFIG_MM_KERNEL_HEAP
+      /* Use the kernel allocator if this is a kernel thread */
+
+      if (ttype == TCB_FLAG_TTYPE_KERNEL)
+        {
+          tcb->stack_alloc_ptr = kmm_memalign(TLS_STACK_ALIGN, stack_size);
+        }
+      else
+#endif
+        {
+          /* Use the user-space allocator if this is a task or pthread */
+
+          tcb->stack_alloc_ptr = kumm_memalign(TLS_STACK_ALIGN, stack_size);
+        }
+
+#else /* CONFIG_TLS_ALIGNED */
+#ifdef CONFIG_MM_KERNEL_HEAP
+      /* Use the kernel allocator if this is a kernel thread */
+
+      if (ttype == TCB_FLAG_TTYPE_KERNEL)
+        {
+          tcb->stack_alloc_ptr = kmm_malloc(stack_size);
+        }
+      else
+#endif
+        {
+          /* Use the user-space allocator if this is a task or pthread */
+
+          tcb->stack_alloc_ptr = kumm_malloc(stack_size);
+        }
+#endif /* CONFIG_TLS_ALIGNED */
+
+#ifdef CONFIG_DEBUG_FEATURES
+      /* Was the allocation successful? */
+
+      if (!tcb->stack_alloc_ptr)
+        {
+          serr("ERROR: Failed to allocate stack, size %d\n", stack_size);
+        }
+#endif
+    }
+
+  /* Did we successfully allocate a stack? */
+
+  if (tcb->stack_alloc_ptr)
+    {
+      /* Yes.. If stack debug is enabled, then fill the stack with a
+       * recognizable value that we can use later to test for high
+       * water marks.
+       */
+
+#ifdef CONFIG_STACK_COLORATION
+      memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
+#endif
+
+      /* Save the adjusted stack values in the struct tcb_s */
+
+      tcb->stack_base_ptr = tcb->stack_alloc_ptr;
+      tcb->adj_stack_size = stack_size;
+      tcb->flags |= TCB_FLAG_FREE_STACK;
+
+#if defined(ARCH_HAVE_LEDS)
+      board_autoled_on(LED_STACKCREATED);
+#endif
+      return OK;
+    }
+
+  return ERROR;
+}
diff --git a/arch/avr/src/avr/avr_doirq.c b/arch/avr/src/avr/avr_doirq.c
new file mode 100644
index 0000000000..9ec194a34e
--- /dev/null
+++ b/arch/avr/src/avr/avr_doirq.c
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_doirq.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <assert.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+uint8_t *avr_doirq(uint8_t irq, uint8_t *regs)
+{
+  board_autoled_on(LED_INIRQ);
+#ifdef CONFIG_SUPPRESS_INTERRUPTS
+  PANIC();
+#else
+  uint8_t *savestate;
+
+  /* Nested interrupts are not supported in this implementation.  If you want
+   * to implement nested interrupts, you would have to (1) change the way
+   * that g_current_regs is handled and (2) the design associated with
+   * CONFIG_ARCH_INTERRUPTSTACK.  The savestate variable will not work for
+   * that purpose as implemented here because only the outermost nested
+   * interrupt can result in a context switch (it can probably be deleted).
+   */
+
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * g_current_regs is also used to manage interrupt level context switches.
+   */
+
+  savestate    = (uint8_t *)g_current_regs;   /* Cast removes volatile attribute */
+  g_current_regs = regs;
+
+  /* Deliver the IRQ */
+
+  irq_dispatch((int)irq, (uint32_t *)regs);
+
+  /* If a context switch occurred while processing the interrupt then
+   * g_current_regs may have change value.  If we return any value different
+   * from the input regs, then the lower level will know that a context
+   * switch occurred during interrupt processing.
+   */
+
+  regs = (uint8_t *)g_current_regs;   /* Cast removes volatile attribute */
+
+  /* Restore the previous value of g_current_regs.  NULL would indicate that
+   * we are no longer in an interrupt handler.  It will be non-NULL if we
+   * are returning from a nested interrupt.
+   */
+
+  g_current_regs = savestate;
+#endif
+  board_autoled_off(LED_INIRQ);
+  return regs;
+}
diff --git a/arch/avr/src/avr/avr_dumpstate.c b/arch/avr/src/avr/avr_dumpstate.c
new file mode 100644
index 0000000000..fce35f0369
--- /dev/null
+++ b/arch/avr/src/avr/avr_dumpstate.c
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_dumpstate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/syslog/syslog.h>
+#include <arch/board/board.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+#ifdef CONFIG_ARCH_STACKDUMP
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_stackdump
+ ****************************************************************************/
+
+static void avr_stackdump(uint16_t sp, uint16_t stack_top)
+{
+  uint16_t stack;
+
+  /* Flush any buffered SYSLOG data to avoid overwrite */
+
+  syslog_flush();
+
+  for (stack = sp & ~0x7; stack < (stack_top & ~0x7); stack += 8)
+    {
+      uint8_t *ptr = (uint8_t *)stack;
+      _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+             stack, ptr[0], ptr[1], ptr[2], ptr[3],
+             ptr[4], ptr[5], ptr[6], ptr[7]);
+    }
+}
+
+/****************************************************************************
+ * Name: avr_registerdump
+ ****************************************************************************/
+
+static inline void avr_registerdump(void)
+{
+  /* Are user registers available from interrupt processing? */
+
+  if (g_current_regs)
+    {
+      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+             0,
+             g_current_regs[REG_R0],  g_current_regs[REG_R1],
+             g_current_regs[REG_R2],  g_current_regs[REG_R3],
+             g_current_regs[REG_R4],  g_current_regs[REG_R5],
+             g_current_regs[REG_R6],  g_current_regs[REG_R7]);
+
+      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+             8,
+             g_current_regs[REG_R8],  g_current_regs[REG_R9],
+             g_current_regs[REG_R10], g_current_regs[REG_R11],
+             g_current_regs[REG_R12], g_current_regs[REG_R13],
+             g_current_regs[REG_R14], g_current_regs[REG_R15]);
+
+      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+             16,
+             g_current_regs[REG_R16], g_current_regs[REG_R17],
+             g_current_regs[REG_R18], g_current_regs[REG_R19],
+             g_current_regs[REG_R20], g_current_regs[REG_R21],
+             g_current_regs[REG_R22], g_current_regs[REG_R23]);
+
+      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+             24,
+             g_current_regs[REG_R24], g_current_regs[REG_R25],
+             g_current_regs[REG_R26], g_current_regs[REG_R27],
+             g_current_regs[REG_R28], g_current_regs[REG_R29],
+             g_current_regs[REG_R30], g_current_regs[REG_R31]);
+
+#if !defined(REG_PC2)
+      _alert("PC:  %02x%02x  SP: %02x%02x SREG: %02x\n",
+             g_current_regs[REG_PC0], g_current_regs[REG_PC1],
+             g_current_regs[REG_SPH], g_current_regs[REG_SPL],
+             g_current_regs[REG_SREG]);
+#else
+      _alert("PC:  %02x%02x%02x  SP: %02x%02x SREG: %02x\n",
+             g_current_regs[REG_PC0], g_current_regs[REG_PC1],
+             g_current_regs[REG_PC2], g_current_regs[REG_SPH],
+             g_current_regs[REG_SPL], g_current_regs[REG_SREG]);
+#endif
+    }
+}
+
+/****************************************************************************
+ * Name: _up_assert
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_dumpstate
+ ****************************************************************************/
+
+void avr_dumpstate(void)
+{
+  FAR struct tcb_s *rtcb = running_task();
+  uint16_t sp = up_getsp();
+  uint16_t ustackbase;
+  uint16_t ustacksize;
+#if CONFIG_ARCH_INTERRUPTSTACK > 0
+  uint16_t istackbase;
+  uint16_t istacksize;
+#endif
+
+  /* Dump the registers (if available) */
+
+  avr_registerdump();
+
+  /* Get the limits on the user stack memory */
+
+  ustackbase = (uint16_t)rtcb->stack_base_ptr;
+  ustacksize = (uint16_t)rtcb->adj_stack_size;
+
+  /* Get the limits on the interrupt stack memory */
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 0
+  istackbase = (uint16_t)g_intstackalloc;
+  istacksize = CONFIG_ARCH_INTERRUPTSTACK;
+
+  /* Show interrupt stack info */
+
+  _alert("sp:     %04x\n", sp);
+  _alert("IRQ stack:\n");
+  _alert("  base: %04x\n", istackbase);
+  _alert("  size: %04x\n", istacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("  used: %08x\n", up_check_intstack());
+#endif
+
+  /* Does the current stack pointer lie within the interrupt
+   * stack?
+   */
+
+  if (sp >= istackbase && sp < istackbase + istacksize)
+    {
+      /* Yes.. dump the interrupt stack */
+
+      avr_stackdump(sp, istackbase + istacksize);
+    }
+  else if (g_current_regs)
+    {
+      _alert("ERROR: Stack pointer is not within the interrupt stack\n");
+      avr_stackdump(istackbase, istackbase + istacksize);
+    }
+
+  /* Extract the user stack pointer if we are in an interrupt handler.
+   * If we are not in an interrupt handler.  Then sp is the user stack
+   * pointer (and the above range check should have failed).
+   */
+
+  if (g_current_regs)
+    {
+      sp = g_current_regs[REG_R13];
+      _alert("sp:     %04x\n", sp);
+    }
+
+  _alert("User stack:\n");
+  _alert("  base: %04x\n", ustackbase);
+  _alert("  size: %04x\n", ustacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("  used: %08x\n", up_check_tcbstack(rtcb));
+#endif
+#else
+  _alert("sp:         %04x\n", sp);
+  _alert("stack base: %04x\n", ustackbase);
+  _alert("stack size: %04x\n", ustacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("stack used: %08x\n", up_check_tcbstack(rtcb));
+#endif
+#endif
+
+  /* Dump the user stack if the stack pointer lies within the allocated user
+   * stack memory.
+   */
+
+  if (sp >= ustackbase && sp < ustackbase + ustacksize)
+    {
+      avr_stackdump(sp, ustackbase + ustacksize);
+    }
+  else
+    {
+      _alert("ERROR: Stack pointer is not within allocated stack\n");
+      avr_stackdump(ustackbase, ustackbase + ustacksize);
+    }
+}
+
+#endif /* CONFIG_ARCH_STACKDUMP */
diff --git a/arch/avr/src/avr/avr_initialstate.c b/arch/avr/src/avr/avr_initialstate.c
new file mode 100644
index 0000000000..d77ebeab36
--- /dev/null
+++ b/arch/avr/src/avr/avr_initialstate.c
@@ -0,0 +1,115 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_initialstate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/arch.h>
+#include <arch/irq.h>
+#include <avr/io.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_initial_state
+ *
+ * Description:
+ *   A new thread is being started and a new TCB has been created. This
+ *   function is called to initialize the processor specific portions of the
+ *   new TCB.
+ *
+ *   This function must setup the initial architecture registers and/or stack
+ *   so that execution will begin at tcb->start  on the next context switch.
+ *
+ ****************************************************************************/
+
+void up_initial_state(struct tcb_s *tcb)
+{
+  struct xcptcontext *xcp = &tcb->xcp;
+  uintptr_t sp;
+
+  /* Initialize the idle thread stack */
+
+  if (tcb->pid == IDLE_PROCESS_ID)
+    {
+      char *stack_ptr = (char *)(g_idle_topstack -
+                                 CONFIG_IDLETHREAD_STACKSIZE);
+#ifdef CONFIG_STACK_COLORATION
+      char *stack_end = (char *)avr_getsp();
+
+      /* If stack debug is enabled, then fill the stack with a
+       * recognizable value that we can use later to test for high
+       * water marks.
+       */
+
+      while (stack_ptr < stack_end)
+        {
+          *--stack_end = STACK_COLOR;
+        }
+#endif /* CONFIG_STACK_COLORATION */
+
+      tcb->stack_alloc_ptr = stack_ptr;
+      tcb->stack_base_ptr  = stack_ptr;
+      tcb->adj_stack_size  = CONFIG_IDLETHREAD_STACKSIZE;
+    }
+
+  /* Initialize the initial exception register context structure.  Zeroing
+   * all registers is a good debug helper, but should not be necessary.
+   */
+
+  memset(xcp, 0, sizeof(struct xcptcontext));
+
+  /* Set the initial stack pointer to the top of the allocated stack */
+
+  sp                   = (uintptr_t)tcb->stack_base_ptr +
+                                    tcb->adj_stack_size;
+  xcp->regs[REG_SPH]   = (uint8_t)(sp >> 8);
+  xcp->regs[REG_SPL]   = (uint8_t)(sp & 0xff);
+
+  /* Save the task entry point */
+
+#if !defined(REG_PC2)
+  xcp->regs[REG_PC0]   = (uint8_t)((uintptr_t)tcb->start >> 8);
+  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
+#else
+  xcp->regs[REG_PC0]   = (uint8_t)((uint32_t)(uintptr_t)tcb->start >> 16);
+  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start >> 8);
+  xcp->regs[REG_PC2]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
+#endif
+
+  /* Enable or disable interrupts, based on user configuration */
+
+#ifdef CONFIG_SUPPRESS_INTERRUPTS
+  xcp->regs[REG_SREG]  = getsreg() & ~(1 << SREG_I);
+#else
+  xcp->regs[REG_SREG]  = getsreg() | (1 << SREG_I);
+#endif
+}
diff --git a/arch/avr/src/avr/avr_irq.c b/arch/avr/src/avr/avr_irq.c
new file mode 100644
index 0000000000..64f4fc5aa2
--- /dev/null
+++ b/arch/avr/src/avr/avr_irq.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_irq.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <arch/irq.h>
+#include <avr/io.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_irqinitialize
+ ****************************************************************************/
+
+void up_irqinitialize(void)
+{
+  /* Initialize GPIO interrupt facilities */
+
+#ifdef CONFIG_AVR32_GPIOIRQ
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
+  if (gpio_irqinitialize != NULL)
+#endif
+    {
+      gpio_irqinitialize();
+    }
+#endif
+
+  /* And finally, enable interrupts */
+
+#ifndef CONFIG_SUPPRESS_INTERRUPTS
+  up_irq_restore(getsreg() | (1 << SREG_I));
+#endif
+}
diff --git a/arch/avr/src/avr/avr_releasepending.c b/arch/avr/src/avr/avr_releasepending.c
new file mode 100644
index 0000000000..7caf24a87e
--- /dev/null
+++ b/arch/avr/src/avr/avr_releasepending.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_releasepending.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sched.h>
+#include <debug.h>
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_release_pending
+ *
+ * Description:
+ *   Release and ready-to-run tasks that have
+ *   collected in the pending task list.  This can call a
+ *   context switch if a new task is placed at the head of
+ *   the ready to run list.
+ *
+ ****************************************************************************/
+
+void up_release_pending(void)
+{
+  struct tcb_s *rtcb = this_task();
+
+  sinfo("From TCB=%p\n", rtcb);
+
+  /* Merge the g_pendingtasks list into the ready-to-run task list */
+
+  if (nxsched_merge_pending())
+    {
+      /* The currently active task has changed!  We will need to switch
+       * contexts.
+       */
+
+      /* Update scheduler parameters */
+
+      nxsched_suspend_scheduler(rtcb);
+
+      if (g_current_regs)
+        {
+          /* Yes, then we have to do things differently.
+           * Just copy the g_current_regs into the OLD rtcb.
+           */
+
+           avr_savestate(rtcb->xcp.regs);
+
+          /* Restore the exception context of the rtcb at the (new) head
+           * of the ready-to-run task list.
+           */
+
+          rtcb = this_task();
+
+          /* Update scheduler parameters */
+
+          nxsched_resume_scheduler(rtcb);
+
+          /* Then switch contexts */
+
+          avr_restorestate(rtcb->xcp.regs);
+        }
+
+      /* No, then we will need to perform the user context switch */
+
+      else
+        {
+          struct tcb_s *nexttcb = this_task();
+
+          /* Update scheduler parameters */
+
+          nxsched_resume_scheduler(nexttcb);
+
+          /* Switch context to the context of the task at the head of the
+           * ready to run list.
+           */
+
+          avr_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
+
+          /* avr_switchcontext forces a context switch to the task at the
+           * head of the ready-to-run list.  It does not 'return' in the
+           * normal sense.  When it does return, it is because the blocked
+           * task is again ready to run and has execution priority.
+           */
+        }
+    }
+}
diff --git a/arch/avr/src/avr/avr_romgetc.c b/arch/avr/src/avr/avr_romgetc.c
new file mode 100644
index 0000000000..88bd368c2a
--- /dev/null
+++ b/arch/avr/src/avr/avr_romgetc.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_romgetc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/arch.h>
+#include <avr/pgmspace.h>
+
+#ifdef CONFIG_ARCH_ROMGETC
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_romgetc
+ *
+ * Description:
+ *   In Harvard architectures, data accesses and instruction accesses occur
+ *   on different buses, perhaps concurrently.  All data accesses are
+ *   performed on the data bus unless special  machine instructions are
+ *   used to read data from the instruction address space.  Also, in the
+ *   typical MCU, the available SRAM data memory is much smaller that the
+ *   non-volatile FLASH instruction memory.  So if the application requires
+ *   many constant strings, the only practical solution may be to store
+ *   those constant strings in FLASH memory where they can only be accessed
+ *   using architecture-specific machine instructions.
+ *
+ *   A similar case is where strings are retained in "external" memory such
+ *   as EEPROM or serial FLASH.  This case is similar only in that again
+ *   special operations are required to obtain the string data; it cannot
+ *   be accessed directly from a string pointer.
+ *
+ *   If CONFIG_ARCH_ROMGETC is defined, then the architecture logic must
+ *   export the function up_romgetc().  up_romgetc() will simply read one
+ *   byte of data from the instruction space.
+ *
+ *   If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected: (1)
+ *   All format strings in printf, fprintf, sprintf, etc. are assumed to
+ *   lie in FLASH (string arguments for %s are still assumed to reside in
+ *   SRAM). And (2), the string argument to puts and fputs is assumed to
+ *   reside in FLASH.  Clearly, these assumptions may have to modified for
+ *   the particular needs of your environment.
+ *   There is no "one-size-fits-all" solution for this problem.
+ *
+ * Additional AVR Assumptions:
+ *
+ * - This version of up_romgetc obtains string data from FLASH memory.
+ * - Since the passed pointer is 16-bits, the strings must lie in the first
+ *   64Kb of FLASH.
+ *
+ ****************************************************************************/
+
+char up_romgetc(FAR const char *ptr)
+{
+  return pgm_read_byte_near(ptr);
+}
+#endif
diff --git a/arch/avr/src/avr/avr_schedulesigaction.c b/arch/avr/src/avr/avr_schedulesigaction.c
new file mode 100644
index 0000000000..ce2a803fe8
--- /dev/null
+++ b/arch/avr/src/avr/avr_schedulesigaction.c
@@ -0,0 +1,194 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_schedulesigaction.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <avr/io.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_schedule_sigaction
+ *
+ * Description:
+ *   This function is called by the OS when one or more
+ *   signal handling actions have been queued for execution.
+ *   The architecture specific code must configure things so
+ *   that the 'sigdeliver' callback is executed on the thread
+ *   specified by 'tcb' as soon as possible.
+ *
+ *   This function may be called from interrupt handling logic.
+ *
+ *   This operation should not cause the task to be unblocked
+ *   nor should it cause any immediate execution of sigdeliver.
+ *   Typically, a few cases need to be considered:
+ *
+ *   (1) This function may be called from an interrupt handler
+ *       During interrupt processing, all xcptcontext structures
+ *       should be valid for all tasks.  That structure should
+ *       be modified to invoke sigdeliver() either on return
+ *       from (this) interrupt or on some subsequent context
+ *       switch to the recipient task.
+ *   (2) If not in an interrupt handler and the tcb is NOT
+ *       the currently executing task, then again just modify
+ *       the saved xcptcontext structure for the recipient
+ *       task so it will invoke sigdeliver when that task is
+ *       later resumed.
+ *   (3) If not in an interrupt handler and the tcb IS the
+ *       currently executing task -- just call the signal
+ *       handler now.
+ *
+ * Assumptions:
+ *   Called from critical section
+ *
+ ****************************************************************************/
+
+void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
+{
+  uintptr_t reg_ptr = (uintptr_t)avr_sigdeliver;
+
+  sinfo("tcb=%p sigdeliver=%p\n", tcb, sigdeliver);
+
+  /* Refuse to handle nested signal actions */
+
+  if (!tcb->xcp.sigdeliver)
+    {
+      /* First, handle some special cases when the signal is
+       * being delivered to the currently executing task.
+       */
+
+      sinfo("rtcb=%p g_current_regs=%p\n",
+            this_task(), g_current_regs);
+
+      if (tcb == this_task())
+        {
+          /* CASE 1:  We are not in an interrupt handler and
+           * a task is signalling itself for some reason.
+           */
+
+          if (!g_current_regs)
+            {
+              /* In this case just deliver the signal now. */
+
+              sigdeliver(tcb);
+            }
+
+          /* CASE 2:  We are in an interrupt handler AND the
+           * interrupted task is the same as the one that
+           * must receive the signal, then we will have to modify
+           * the return state as well as the state in the TCB.
+           *
+           * Hmmm... there looks like a latent bug here: The following
+           * logic would fail in the strange case where we are in an
+           * interrupt handler, the thread is signalling itself, but
+           * a context switch to another task has occurred so that
+           * g_current_regs does not refer to the thread of this_task()!
+           */
+
+          else
+            {
+              /* Save registers that must be protected while the signal
+               * handler runs. These will be restored by the signal
+               * trampoline after the signal(s) have been delivered.
+               */
+
+              tcb->xcp.sigdeliver   = sigdeliver;
+              tcb->xcp.saved_pc0    = g_current_regs[REG_PC0];
+              tcb->xcp.saved_pc1    = g_current_regs[REG_PC1];
+#if defined(REG_PC2)
+              tcb->xcp.saved_pc2    = g_current_regs[REG_PC2];
+#endif
+              tcb->xcp.saved_sreg   = g_current_regs[REG_SREG];
+
+              /* Then set up to vector to the trampoline with interrupts
+               * disabled
+               */
+
+#if !defined(REG_PC2)
+              g_current_regs[REG_PC0] = (uint16_t)reg_ptr >> 8;
+              g_current_regs[REG_PC1] = (uint16_t)reg_ptr & 0xff;
+#else
+              g_current_regs[REG_PC0] = (uint32_t)reg_ptr >> 16;
+              g_current_regs[REG_PC1] = (uint32_t)reg_ptr >> 8;
+              g_current_regs[REG_PC2] = (uint32_t)reg_ptr & 0xff;
+#endif
+              g_current_regs[REG_SREG] &= ~(1 << SREG_I);
+
+              /* And make sure that the saved context in the TCB
+               * is the same as the interrupt return context.
+               */
+
+              avr_savestate(tcb->xcp.regs);
+            }
+        }
+
+      /* Otherwise, we are (1) signaling a task is not running
+       * from an interrupt handler or (2) we are not in an
+       * interrupt handler and the running task is signalling
+       * some non-running task.
+       */
+
+      else
+        {
+          /* Save registers that must be protected while the signal handler
+           * runs. These will be restored by the signal trampoline after
+           * the signals have been delivered.
+           */
+
+          tcb->xcp.sigdeliver       = sigdeliver;
+          tcb->xcp.saved_pc0        = tcb->xcp.regs[REG_PC0];
+          tcb->xcp.saved_pc1        = tcb->xcp.regs[REG_PC1];
+#if defined(REG_PC2)
+          tcb->xcp.saved_pc2        = tcb->xcp.regs[REG_PC2];
+#endif
+          tcb->xcp.saved_sreg       = tcb->xcp.regs[REG_SREG];
+
+          /* Then set up to vector to the trampoline with interrupts
+           * disabled
+           */
+
+#if !defined(REG_PC2)
+          tcb->xcp.regs[REG_PC0]    = (uint16_t)reg_ptr >> 8;
+          tcb->xcp.regs[REG_PC1]    = (uint16_t)reg_ptr & 0xff;
+#else
+          tcb->xcp.regs[REG_PC0]    = (uint32_t)reg_ptr >> 16;
+          tcb->xcp.regs[REG_PC1]    = (uint32_t)reg_ptr >> 8;
+          tcb->xcp.regs[REG_PC2]    = (uint32_t)reg_ptr & 0xff;
+
+#endif
+          tcb->xcp.regs[REG_SREG]  &= ~(1 << SREG_I);
+        }
+    }
+}
diff --git a/arch/avr/src/avr/avr_sigdeliver.c b/arch/avr/src/avr/avr_sigdeliver.c
new file mode 100644
index 0000000000..24b56fc8ee
--- /dev/null
+++ b/arch/avr/src/avr/avr_sigdeliver.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_sigdeliver.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_sigdeliver
+ *
+ * Description:
+ *   This is the a signal handling trampoline.  When a signal action was
+ *   posted.  The task context was mucked with and forced to branch to this
+ *   location with interrupts disabled.
+ *
+ ****************************************************************************/
+
+void avr_sigdeliver(void)
+{
+  struct tcb_s *rtcb = this_task();
+  uint8_t regs[XCPTCONTEXT_REGS];
+
+  board_autoled_on(LED_SIGNAL);
+
+  sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
+        rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head);
+  DEBUGASSERT(rtcb->xcp.sigdeliver != NULL);
+
+  /* Save the return state on the stack. */
+
+  avr_copystate(regs, rtcb->xcp.regs);
+
+#ifndef CONFIG_SUPPRESS_INTERRUPTS
+  /* Then make sure that interrupts are enabled.  Signal handlers must always
+   * run with interrupts enabled.
+   */
+
+  up_irq_enable();
+#endif
+
+  /* Deliver the signal */
+
+  ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+
+  /* Output any debug messages BEFORE restoring errno (because they may
+   * alter errno), then disable interrupts again and restore the original
+   * errno that is needed by the user logic (it is probably EINTR).
+   */
+
+  sinfo("Resuming\n");
+  up_irq_save();
+
+  /* Modify the saved return state with the actual saved values in the
+   * TCB.  This depends on the fact that nested signal handling is
+   * not supported.  Therefore, these values will persist throughout the
+   * signal handling action.
+   *
+   * Keeping this data in the TCB resolves a security problem in protected
+   * and kernel mode:  The regs[] array is visible on the user stack and
+   * could be modified by a hostile program.
+   */
+
+  regs[REG_PC0]        = rtcb->xcp.saved_pc0;
+  regs[REG_PC1]        = rtcb->xcp.saved_pc1;
+#if defined(REG_PC2)
+  regs[REG_PC2]        = rtcb->xcp.saved_pc2;
+#endif
+  regs[REG_SREG]       = rtcb->xcp.saved_sreg;
+  rtcb->xcp.sigdeliver = NULL;  /* Allows next handler to be scheduled */
+
+  /* Then restore the correct state for this thread of execution. This is an
+   * unusual case that must be handled by up_fullcontextresore. This case is
+   * unusual in two ways:
+   *
+   *   1. It is not a context switch between threads.  Rather,
+   *      avr_fullcontextrestore must behave more it more like a longjmp
+   *      within the same task, using the same stack.
+   *   2. In this case, avr_fullcontextrestore is called with r12 pointing to
+   *      a register save area on the stack to be destroyed.  This is
+   *      dangerous because there is the very real possibility that the new
+   *      stack pointer might overlap with the register save area and that
+   *      stack usage in avr_fullcontextrestore might corrupt the register
+   *      save data before the state is restored.  At present, there does
+   *      not appear to be any stack overlap problems.  If there were, then
+   *      adding 3 words to the size of register save structure size will
+   *      protect its contents.
+   */
+
+  board_autoled_off(LED_SIGNAL);
+  avr_fullcontextrestore(regs);
+}
diff --git a/arch/avr/src/avr/avr_spi.c b/arch/avr/src/avr/avr_spi.c
new file mode 100644
index 0000000000..83da03248c
--- /dev/null
+++ b/arch/avr/src/avr/avr_spi.c
@@ -0,0 +1,488 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_spi.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <arch/board/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/mutex.h>
+#include <nuttx/spi/spi.h>
+
+#include <avr/io.h>
+#include <avr/power.h>
+
+#include "avr_internal.h"
+#include "chip.h"
+#include "avr.h"
+
+#ifdef CONFIG_AVR_SPI
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct avr_spidev_s
+{
+  struct spi_dev_s spidev;     /* Externally visible part of the SPI interface */
+  mutex_t          lock;       /* Held while chip is selected for mutual exclusion */
+  uint32_t         frequency;  /* Requested clock frequency */
+  uint32_t         actual;     /* Actual clock frequency */
+  uint8_t          mode;       /* Mode 0,1,2,3 */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* SPI methods */
+
+static int      spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
+                                 uint32_t frequency);
+static void     spi_setmode(FAR struct spi_dev_s *dev,
+                            enum spi_mode_e mode);
+static void     spi_setbits(FAR struct spi_dev_s *dev, int nbits);
+static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
+static void     spi_sndblock(FAR struct spi_dev_s *dev,
+                             FAR const void *buffer, size_t nwords);
+static void     spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer,
+                              size_t nwords);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct spi_ops_s g_spiops =
+{
+  .lock              = spi_lock,
+  .select            = avr_spiselect,
+  .setfrequency      = spi_setfrequency,
+  .setmode           = spi_setmode,
+  .setbits           = spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+  .hwfeatures        = 0,                 /* Not supported */
+#endif
+  .status            = avr_spistatus,
+#ifdef CONFIG_SPI_CMDDATA
+  .cmddata           = avr_spicmddata,
+#endif
+  .send              = spi_send,
+  .sndblock          = spi_sndblock,
+  .recvblock         = spi_recvblock,
+  .registercallback  = 0,                 /* Not implemented */
+};
+
+static struct avr_spidev_s g_spidev =
+{
+  .spidev            =
+  {
+    .ops             = &g_spiops,
+  },
+  .lock              = NXMUTEX_INITIALIZER,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: spi_lock
+ *
+ * Description:
+ *   On SPI buses where there are multiple devices, it will be necessary to
+ *   lock SPI to have exclusive access to the buses for a sequence of
+ *   transfers.  The bus should be locked before the chip is selected. After
+ *   locking the SPI bus, the caller should then also call the setfrequency,
+ *   setbits, and setmode methods to make sure that the SPI is properly
+ *   configured for the device.  If the SPI bus is being shared, then it
+ *   may have been left in an incompatible state.
+ *
+ * Input Parameters:
+ *   dev  - Device-specific state data
+ *   lock - true: Lock spi bus, false: unlock SPI bus
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
+{
+  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
+  int ret;
+
+  if (lock)
+    {
+      ret = nxmutex_lock(&priv->lock);
+    }
+  else
+    {
+      ret = nxmutex_unlock(&priv->lock);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: spi_setfrequency
+ *
+ * Description:
+ *   Set the SPI frequency.
+ *
+ * Input Parameters:
+ *   dev -       Device-specific state data
+ *   frequency - The SPI frequency requested
+ *
+ * Returned Value:
+ *   Returns the actual frequency selected
+ *
+ ****************************************************************************/
+
+static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
+                                 uint32_t frequency)
+{
+  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
+  uint32_t actual;
+
+  /* TODO: This is missing the actual logic to update the frequency.
+   * The divider bits are computed but not actually used.
+   */
+
+  /* Has the request frequency changed? */
+
+  if (frequency != priv->frequency)
+    {
+      /* Read the SPI status and control registers, clearing all div bits */
+
+      uint8_t spcr = SPCR & ~((1 << SPR0) | (1 << SPR1));
+      uint8_t spsr = SPSR & ~(1 << SPI2X);
+
+      /* Select the best divider bits */
+
+      if (frequency >= BOARD_CPU_CLOCK / 2)
+        {
+          spsr  |= (1 << SPI2X);
+          actual = BOARD_CPU_CLOCK / 2;
+        }
+      else if (frequency >= BOARD_CPU_CLOCK / 4)
+        {
+          actual = BOARD_CPU_CLOCK / 4;
+        }
+      else if (frequency >= BOARD_CPU_CLOCK / 8)
+        {
+          spcr  |= (1 << SPR0);
+          spsr  |= (1 << SPI2X);
+          actual = BOARD_CPU_CLOCK / 8;
+        }
+      else if (frequency >= BOARD_CPU_CLOCK / 16)
+        {
+          spcr  |= (1 << SPR0);
+          actual = BOARD_CPU_CLOCK / 16;
+        }
+      else if (frequency >= BOARD_CPU_CLOCK / 32)
+        {
+          spcr  |= (1 << SPR1);
+          spsr  |= (1 << SPI2X);
+          actual = BOARD_CPU_CLOCK / 32;
+        }
+      else if (frequency >= BOARD_CPU_CLOCK / 64)
+        {
+          spcr  |= (1 << SPR1);
+          actual = BOARD_CPU_CLOCK / 64;
+        }
+      else /* if (frequency >= BOARD_CPU_CLOCK / 128) */
+        {
+          spcr  |= (1 << SPR0) | (1 << SPR1);
+          actual = BOARD_CPU_CLOCK / 128;
+        }
+
+      /* Save the frequency setting */
+
+      priv->frequency = frequency;
+      priv->actual    = actual;
+    }
+  else
+    {
+      actual          = priv->actual;
+    }
+
+  spiinfo("Frequency %" PRId32 "->%" PRId32 "\n", frequency, actual);
+  return actual;
+}
+
+/****************************************************************************
+ * Name: spi_setmode
+ *
+ * Description:
+ *   Set the SPI mode. Optional.  See enum spi_mode_e for mode definitions
+ *
+ * Input Parameters:
+ *   dev -  Device-specific state data
+ *   mode - The SPI mode requested
+ *
+ * Returned Value:
+ *   none
+ *
+ ****************************************************************************/
+
+static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode)
+{
+  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
+
+  /* Has the mode changed? */
+
+  if (mode != priv->mode)
+    {
+      uint8_t regval;
+
+      /* Yes... Set SPI CR appropriately */
+
+      regval = SPCR;
+      regval &= ~((1 << CPOL) | (1 << CPHA));
+
+      switch (mode)
+        {
+        case SPIDEV_MODE0: /* CPOL=0; CPHA=0 */
+          break;
+
+        case SPIDEV_MODE1: /* CPOL=0; CPHA=1 */
+          regval |= (1 << CPHA);
+          break;
+
+        case SPIDEV_MODE2: /* CPOL=1; CPHA=0 */
+          regval |= (1 << CPOL);
+          break;
+
+        case SPIDEV_MODE3: /* CPOL=1; CPHA=1 */
+          regval |= ((1 << CPOL) | (1 << CPHA));
+          break;
+
+        default:
+          DEBUGASSERT(FALSE);
+          return;
+        }
+
+      SPSR = regval;
+
+      /* Save the mode so that subsequent re-configurations will be faster */
+
+      priv->mode = mode;
+    }
+}
+
+/****************************************************************************
+ * Name: spi_setbits
+ *
+ * Description:
+ *   Set the number if bits per word.
+ *
+ * Input Parameters:
+ *   dev -  Device-specific state data
+ *   nbits - The number of bits requested (only nbits == 8 is supported)
+ *
+ * Returned Value:
+ *   none
+ *
+ ****************************************************************************/
+
+static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
+{
+  DEBUGASSERT(dev && nbits == 8);
+}
+
+/****************************************************************************
+ * Name: spi_send
+ *
+ * Description:
+ *   Exchange one word on SPI
+ *
+ * Input Parameters:
+ *   dev - Device-specific state data
+ *   wd  - The word to send.  the size of the data is determined by the
+ *         number of bits selected for the SPI interface.
+ *
+ * Returned Value:
+ *   response
+ *
+ ****************************************************************************/
+
+static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd)
+{
+  /* Write the data to transmitted to the SPI Data Register */
+
+  SPDR = (uint8_t)wd;
+
+  /* Wait for transmission to complete */
+
+  while (!(SPSR & (1 << SPIF)));
+
+  /* Then return the received value */
+
+  return (uint32_t)SPDR;
+}
+
+/****************************************************************************
+ * Name: spi_sndblock
+ *
+ * Description:
+ *   Send a block of data on SPI
+ *
+ * Input Parameters:
+ *   dev -    Device-specific state data
+ *   buffer - A pointer to the buffer of data to be sent
+ *   nwords - the length of data to send from the buffer in number of words.
+ *            The wordsize is determined by the number of bits-per-word
+ *            selected for the SPI interface.  If nbits <= 8, the data is
+ *            packed into uint8_t's; if nbits >8, the data is packed into
+ *            uint16_t's
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer,
+                         size_t nwords)
+{
+  FAR uint8_t *ptr = (FAR uint8_t *)buffer;
+
+  spiinfo("nwords: %d\n", nwords);
+  while (nwords-- > 0)
+    {
+      spi_send(dev, (uint16_t)*ptr++);
+    }
+}
+
+/****************************************************************************
+ * Name: spi_recvblock
+ *
+ * Description:
+ *   Revice a block of data from SPI
+ *
+ * Input Parameters:
+ *   dev -    Device-specific state data
+ *   buffer - A pointer to the buffer in which to receive data
+ *   nwords - the length of data that can be received in the buffer in number
+ *            of words.  The wordsize is determined by the number of bits-
+ *            per-wordselected for the SPI interface.  If nbits <= 8, the
+ *            data is packed into uint8_t's; if nbits >8, the data is packed
+ *            into uint16_t's
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer,
+                          size_t nwords)
+{
+  FAR uint8_t *ptr = (FAR uint8_t *)buffer;
+
+  spiinfo("nwords: %d\n", nwords);
+  while (nwords-- > 0)
+    {
+      *ptr++ = spi_send(dev, (uint16_t)0xff);
+    }
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_spibus_initialize
+ *
+ * Description:
+ *   Initialize the selected SPI port
+ *
+ * Input Parameters:
+ *   Port number (for hardware that has multiple SPI interfaces)
+ *
+ * Returned Value:
+ *   Valid SPI device structure reference on success; a NULL on failure
+ *
+ ****************************************************************************/
+
+FAR struct spi_dev_s *avr_spibus_initialize(int port)
+{
+  FAR struct avr_spidev_s *priv = &g_spidev;
+  irqstate_t flags;
+  uint8_t regval;
+
+  /* Make sure that clocks are provided to the SPI module */
+
+  flags = enter_critical_section();
+  power_spi_enable();
+
+  /* Set MOSI and SCK as outputs, all others are inputs (default on reset):
+   *
+   * PB3: PDO/MISO/PCINT3
+   * PB2: PDI/MOSI/PCINT2
+   * PB1: SCK/PCINT1
+   * PB0: SS/PCINT0
+   */
+
+  DDRB |= (1 << 2) | (1 << 1);
+
+  /* - Enable SPI
+   * - Set Master
+   * - Set clock rate oscillator/4
+   * - Set CPOL for SPI clock mode 0
+   */
+
+  SPCR = (1 << SPE) | (1 << MSTR);
+
+  /* Set clock rate to f(osc)/8 */
+
+  /* SPSR |= (1 << 0); */
+
+  /* Clear status flags by reading them */
+
+  regval = SPSR;
+  UNUSED(regval);
+  regval = SPDR;
+  UNUSED(regval);
+
+  /* Set the initial SPI configuration */
+
+  priv->frequency = 0;
+  priv->mode      = SPIDEV_MODE0;
+
+  /* Select a default frequency of approx. 400KHz */
+
+  spi_setfrequency((FAR struct spi_dev_s *)priv, 400000);
+
+  leave_critical_section(flags);
+  return &priv->spidev;
+}
+#endif /* CONFIG_AVR_SPI */
diff --git a/arch/avr/src/avr/avr_stackframe.c b/arch/avr/src/avr/avr_stackframe.c
new file mode 100644
index 0000000000..3ddeffd1d4
--- /dev/null
+++ b/arch/avr/src/avr/avr_stackframe.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_stackframe.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <arch/irq.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_stack_frame
+ *
+ * Description:
+ *   Allocate a stack frame in the TCB's stack to hold thread-specific data.
+ *   This function may be called anytime after up_create_stack() or
+ *   up_use_stack() have been called but before the task has been started.
+ *
+ *   Thread data may be kept in the stack (instead of in the TCB) if it is
+ *   accessed by the user code directly.  This includes such things as
+ *   argv[].  The stack memory is guaranteed to be in the same protection
+ *   domain as the thread.
+ *
+ *   The following TCB fields will be re-initialized:
+ *
+ *   - adj_stack_size: Stack size after removal of the stack frame from
+ *     the stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb:  The TCB of new task
+ *   - frame_size:  The size of the stack frame to allocate.
+ *
+ *  Returned Value:
+ *   - A pointer to bottom of the allocated stack frame.  NULL will be
+ *     returned on any failures.  The alignment of the returned value is
+ *     the same as the alignment of the stack itself.
+ *
+ ****************************************************************************/
+
+FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
+{
+  FAR void *ret;
+
+  /* Is there already a stack allocated? Is it big enough? */
+
+  if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
+    {
+      return NULL;
+    }
+
+  ret = tcb->stack_base_ptr;
+  memset(ret, 0, frame_size);
+
+  /* Save the adjusted stack values in the struct tcb_s */
+
+  tcb->stack_base_ptr  = (FAR uint8_t *)tcb->stack_base_ptr + frame_size;
+  tcb->adj_stack_size -= frame_size;
+
+  /* And return the pointer to the allocated region */
+
+  return ret;
+}
diff --git a/arch/avr/src/avr/avr_switchcontext.S b/arch/avr/src/avr/avr_switchcontext.S
new file mode 100644
index 0000000000..61b26789e3
--- /dev/null
+++ b/arch/avr/src/avr/avr_switchcontext.S
@@ -0,0 +1,123 @@
+/************************************************************************************
+ * arch/avr/src/avr/avr_switchcontext.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ************************************************************************************/
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <arch/irq.h>
+
+#include "excptmacros.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Symbols
+ ************************************************************************************/
+
+	.file		"avr_switchcontext.S"
+
+/************************************************************************************
+ * Macros
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: avr_switchcontext
+ *
+ * Description:
+ *   Save the current thread context and restore the specified context.  The full
+ *   C function prototype is:
+ *
+ *   void avr_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
+ *
+ * On Entry:
+ *   r24-r25: savregs
+ *   r22-r23: restoreregs
+ *
+ * Returned Value:
+ *   avr_switchcontext forces a context switch to the task "canned" in restoreregs.
+ *   It does not 'return' in the normal sense, rather, it will context switch back
+ *   to the function point.  When it does 'return,' it is because the blocked
+ *   task hat was "pickeled" in the saveregs "can" is again ready to run and has
+ *   execution priority.
+ *
+ * Assumptions:
+ *   global interrupts disabled by the caller.
+ *
+ ************************************************************************************/
+
+	.text
+	.globl	avr_switchcontext
+	.func	avr_switchcontext
+avr_switchcontext:
+	/* Use X [r26:r27] to reference the save structure.  (X is Call-used) */
+
+	movw	r26, r24
+
+	/* Save the context to saveregs */
+
+	USER_SAVE
+
+	/* Then fall through to do the full context restore with r24-r5 = restoreregs */
+
+	movw	r24, r22
+	.endfunc
+
+/****************************************************************************
+ * Name: avr_fullcontextrestore
+ *
+ * Description:
+ *   Restore the full-running context of a thread.
+ *
+ * Input Parameters:
+ *   r24-r25 = A pointer to the register save area of the thread to be restored.
+ *
+ * C Prototype:
+ *  void avr_fullcontextrestore(uint8_t *regs);
+ *
+ * Assumptions:
+ *   Interrupts are disabled.
+ *
+ ****************************************************************************/
+
+	.text
+	.global	avr_fullcontextrestore
+	.func	avr_fullcontextrestore
+avr_fullcontextrestore:
+	/* Use X [r26:r27] to reference the restore structure.  */
+
+	movw	r26, r24
+
+	/* Restore the context from the TCB saved registers */
+
+	TCB_RESTORE
+
+	/* Returning from the function is handled in TCB_RESTORE */
+
+	.endfunc
+	.end
diff --git a/arch/avr/src/avr/avr_unblocktask.c b/arch/avr/src/avr/avr_unblocktask.c
new file mode 100644
index 0000000000..00ee9cc206
--- /dev/null
+++ b/arch/avr/src/avr/avr_unblocktask.c
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_unblocktask.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "clock/clock.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_unblock_task
+ *
+ * Description:
+ *   A task is currently in the ready-to-run list but has been prepped
+ *   to execute. Restore its context, and start execution.
+ *
+ * Input Parameters:
+ *   tcb: Refers to the head task of the ready-to-run list
+ *     which will be executed.
+ *   rtcb: Refers to the running task which will be blocked.
+ *
+ ****************************************************************************/
+
+void up_unblock_task(struct tcb_s *tcb, struct tcb_s *rtcb)
+{
+  /* Update scheduler parameters */
+
+  nxsched_suspend_scheduler(rtcb);
+
+  /* Are we in an interrupt handler? */
+
+  if (g_current_regs)
+    {
+      /* Yes, then we have to do things differently.
+       * Just copy the g_current_regs into the OLD rtcb.
+       */
+
+      avr_savestate(rtcb->xcp.regs);
+
+      /* Update scheduler parameters */
+
+      nxsched_resume_scheduler(tcb);
+
+      /* Then switch contexts */
+
+      avr_restorestate(tcb->xcp.regs);
+    }
+
+  /* No, then we will need to perform the user context switch */
+
+  else
+    {
+      /* Update scheduler parameters */
+
+      nxsched_resume_scheduler(tcb);
+
+      /* Switch context to the context of the task at the head of the
+       * ready to run list.
+       */
+
+      avr_switchcontext(rtcb->xcp.regs, tcb->xcp.regs);
+
+      /* avr_switchcontext forces a context switch to the task at the
+       * head of the ready-to-run list.  It does not 'return' in the
+       * normal sense.  When it does return, it is because the blocked
+       * task is again ready to run and has execution priority.
+       */
+    }
+}
diff --git a/arch/avr/src/avr/avr_usestack.c b/arch/avr/src/avr/avr_usestack.c
new file mode 100644
index 0000000000..d49d65a817
--- /dev/null
+++ b/arch/avr/src/avr/avr_usestack.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * arch/avr/src/avr/avr_usestack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ *   Setup up stack-related information in the TCB using pre-allocated stack
+ *   memory.  This function is called only from nxtask_init() when a task or
+ *   kernel thread is started (never for pthreads).
+ *
+ *   The following TCB fields must be initialized:
+ *
+ *   - adj_stack_size: Stack size after adjustment for hardware,
+ *     processor, etc.  This value is retained only for debug
+ *     purposes.
+ *   - stack_alloc_ptr: Pointer to allocated stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb: The TCB of new task
+ *   - stack_size:  The allocated stack size.
+ *
+ *   NOTE:  Unlike up_stack_create() and up_stack_release, this function
+ *   does not require the task type (ttype) parameter.  The TCB flags will
+ *   always be set to provide the task type to up_use_stack() if it needs
+ *   that information.
+ *
+ ****************************************************************************/
+
+int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
+{
+#ifdef CONFIG_TLS_ALIGNED
+  /* Make certain that the user provided stack is properly aligned */
+
+  DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
+#endif
+
+  /* Is there already a stack allocated? */
+
+  if (tcb->stack_alloc_ptr)
+    {
+      /* Yes.. Release the old stack allocation */
+
+      up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
+    }
+
+  /* Save the new stack allocation */
+
+  tcb->stack_alloc_ptr = stack;
+
+  /* If stack debug is enabled, then fill the stack with a recognizable value
+   * that we can use later to test for high water marks.
+   */
+
+#ifdef CONFIG_STACK_COLORATION
+  memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
+#endif
+
+  /* The AVR uses a push-down stack:  the stack grows toward loweraddresses
+   * in memory.  The stack pointer register, points to the lowest, valid work
+   * address (the "top" of the stack).  Items on the stack are referenced as
+   * positive word offsets from sp.
+   */
+
+  /* Save the adjusted stack values in the struct tcb_s */
+
+  tcb->stack_base_ptr = tcb->stack_alloc_ptr;
+  tcb->adj_stack_size = stack_size;
+
+  return OK;
+}
diff --git a/arch/avr/src/avr/excptmacros.h b/arch/avr/src/avr/excptmacros.h
index d61cf6f4d5..d301fbabc0 100644
--- a/arch/avr/src/avr/excptmacros.h
+++ b/arch/avr/src/avr/excptmacros.h
@@ -546,7 +546,7 @@
    * interrupt_enable - return sequence.
    *
    * NOTE: since actual returning is handled by this macro it has been
-   * removed from up_fullcontextrestore function (up_switchcontext.S)
+   * removed from avr_fullcontextrestore function (avr_switchcontext.S)
    */
 
   /* If interrupts shall be enabled go to 'restore remaining and reti' code
diff --git a/arch/avr/src/avr/up_blocktask.c b/arch/avr/src/avr/up_blocktask.c
deleted file mode 100644
index 02d3a5b877..0000000000
--- a/arch/avr/src/avr/up_blocktask.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_blocktask.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdbool.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/sched.h>
-
-#include "sched/sched.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_block_task
- *
- * Description:
- *   The currently executing task has already removed from ready-to-run list.
- *   Save its context and switch to the next running task at the head of the
- *   ready-to-run list.
- *
- * Input Parameters:
- *   rtcb: Reference to the running task which is different to the
- *     task (next running task) at the head of the list.
- *
- ****************************************************************************/
-
-void up_block_task(struct tcb_s *rtcb)
-{
-  /* Update scheduler parameters */
-
-  nxsched_suspend_scheduler(rtcb);
-
-  /* Are we in an interrupt handler? */
-
-  if (g_current_regs)
-    {
-      /* Yes, then we have to do things differently.
-       * Just copy the g_current_regs into the OLD rtcb.
-       */
-
-      up_savestate(rtcb->xcp.regs);
-
-      /* Restore the exception context of the rtcb at the (new) head
-       * of the ready-to-run task list.
-       */
-
-      rtcb = this_task();
-
-      /* Reset scheduler parameters */
-
-      nxsched_resume_scheduler(rtcb);
-
-      /* Then switch contexts */
-
-      up_restorestate(rtcb->xcp.regs);
-    }
-
-  /* No, then we will need to perform the user context switch */
-
-  else
-    {
-      struct tcb_s *nexttcb = this_task();
-
-      /* Reset scheduler parameters */
-
-      nxsched_resume_scheduler(nexttcb);
-
-      /* Switch context to the context of the task at the head of the
-       * ready to run list.
-       */
-
-      up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
-
-      /* up_switchcontext forces a context switch to the task at the
-       * head of the ready-to-run list.  It does not 'return' in the
-       * normal sense.  When it does return, it is because the blocked
-       * task is again ready to run and has execution priority.
-       */
-    }
-}
diff --git a/arch/avr/src/avr/up_checkstack.c b/arch/avr/src/avr/up_checkstack.c
deleted file mode 100644
index b54421773b..0000000000
--- a/arch/avr/src/avr/up_checkstack.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_checkstack.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <sched.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/board.h>
-
-#include "up_internal.h"
-#include "sched/sched.h"
-
-#ifdef CONFIG_STACK_COLORATION
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: avr_stack_check
- *
- * Description:
- *   Determine (approximately) how much stack has been used be searching the
- *   stack memory for a high water mark.  That is, the deepest level of the
- *   stack that clobbered some recognizable marker in the stack memory.
- *
- * Input Parameters:
- *   alloc - Allocation base address of the stack
- *   size - The size of the stack in bytes
- *
- * Returned Value:
- *   The estimated amount of stack space used.
- *
- ****************************************************************************/
-
-size_t avr_stack_check(uintptr_t alloc, size_t size)
-{
-  FAR uint8_t *ptr;
-  size_t mark;
-#if 0
-  int i;
-  int j;
-#endif
-
-  /* The AVR uses a push-down stack:  the stack grows toward lower addresses
-   * in memory.  We need to start at the lowest address in the stack memory
-   * allocation and search to higher addresses.  The first byte we encounter
-   * that does not have the magic value is the high water mark.
-   */
-
-  for (ptr = (FAR uint8_t *)alloc, mark = size;
-       *ptr == STACK_COLOR && mark > 0;
-       ptr++, mark--);
-
-  /* If the stack is completely used, then this might mean that the stack
-   * overflowed from above (meaning that the stack is too small), or may
-   * have been overwritten from below meaning that some other stack or data
-   * structure overflowed.
-   *
-   * If you see returned values saying that the entire stack is being used
-   * then enable the following logic to see it there are unused areas in the
-   * middle of the stack.
-   */
-
-#if 0
-  if (mark + 16 > size)
-    {
-      ptr = (FAR uint8_t *)alloc;
-      for (i = 0; i < size; i += 64)
-        {
-          for (j = 0; j < 64; j++)
-            {
-              int ch;
-              if (*ptr++ == STACK_COLOR)
-                {
-                  ch = '.';
-                }
-              else
-                {
-                  ch = 'X';
-                }
-
-              up_putc(ch);
-            }
-
-          up_putc('\n');
-        }
-    }
-#endif
-
-  /* Return our guess about how much stack space was used */
-
-  return mark;
-}
-
-/****************************************************************************
- * Name: up_check_stack and friends
- *
- * Description:
- *   Determine (approximately) how much stack has been used be searching the
- *   stack memory for a high water mark.  That is, the deepest level of the
- *   stack that clobbered some recognizable marker in the stack memory.
- *
- * Input Parameters:
- *   None
- *
- * Returned Value:
- *   The estimated amount of stack space used.
- *
- ****************************************************************************/
-
-size_t up_check_tcbstack(FAR struct tcb_s *tcb)
-{
-  return avr_stack_check((uintptr_t)tcb->stack_base_ptr,
-                         tcb->adj_stack_size);
-}
-
-ssize_t up_check_tcbstack_remain(FAR struct tcb_s *tcb)
-{
-  return tcb->adj_stack_size - up_check_tcbstack(tcb);
-}
-
-size_t up_check_stack(void)
-{
-  return up_check_tcbstack(running_task());
-}
-
-ssize_t up_check_stack_remain(void)
-{
-  return up_check_tcbstack_remain(running_task());
-}
-
-#if CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(void)
-{
-  uintptr_t start = (uintptr_t)g_intstackalloc;
-  return avr_stack_check(start, CONFIG_ARCH_INTERRUPTSTACK & ~3);
-}
-
-size_t up_check_intstack_remain(void)
-{
-  return (CONFIG_ARCH_INTERRUPTSTACK & ~3) - up_check_intstack();
-}
-#endif
-
-#endif /* CONFIG_STACK_COLORATION */
diff --git a/arch/avr/src/avr/up_copystate.c b/arch/avr/src/avr/up_copystate.c
deleted file mode 100644
index acbc924fb7..0000000000
--- a/arch/avr/src/avr/up_copystate.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_copystate.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <arch/irq.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_copystate
- ****************************************************************************/
-
-/* Really just a memcpy */
-
-void up_copystate(uint8_t *dest, uint8_t *src)
-{
-  int i;
-
-  /* The state is copied from the stack to the TCB, but only a reference is
-   * passed to get the state from the TCB.  So the following check avoids
-   * copying the TCB save area onto itself:
-   */
-
-  if (src != dest)
-    {
-      for (i = 0; i < XCPTCONTEXT_REGS; i++)
-        {
-          *dest++ = *src++;
-        }
-    }
-}
diff --git a/arch/avr/src/avr/up_createstack.c b/arch/avr/src/avr/up_createstack.c
deleted file mode 100644
index 24b83de6c6..0000000000
--- a/arch/avr/src/avr/up_createstack.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_createstack.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/compiler.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/arch.h>
-#include <nuttx/tls.h>
-#include <arch/board/board.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_create_stack
- *
- * Description:
- *   Allocate a stack for a new thread and setup up stack-related information
- *   in the TCB.
- *
- *   The following TCB fields must be initialized by this function:
- *
- *   - adj_stack_size: Stack size after adjustment for hardware, processor,
- *     etc.  This value is retained only for debug purposes.
- *   - stack_alloc_ptr: Pointer to allocated stack
- *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
- *     Arguments has been removed from the stack allocation.
- *
- * Input Parameters:
- *   - tcb: The TCB of new task
- *   - stack_size:  The requested stack size.  At least this much
- *     must be allocated.
- *   - ttype:  The thread type.  This may be one of following (defined in
- *     include/nuttx/sched.h):
- *
- *       TCB_FLAG_TTYPE_TASK     Normal user task
- *       TCB_FLAG_TTYPE_PTHREAD  User pthread
- *       TCB_FLAG_TTYPE_KERNEL   Kernel thread
- *
- *     This thread type is normally available in the flags field of the TCB,
- *     however, there are certain contexts where the TCB may not be fully
- *     initialized when up_create_stack is called.
- *
- ****************************************************************************/
-
-int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
-{
-#ifdef CONFIG_TLS_ALIGNED
-  /* The allocated stack size must not exceed the maximum possible for the
-   * TLS feature.
-   */
-
-  DEBUGASSERT(stack_size <= TLS_MAXSTACK);
-  if (stack_size >= TLS_MAXSTACK)
-    {
-      stack_size = TLS_MAXSTACK;
-    }
-#endif
-
-  /* Is there already a stack allocated of a different size?  Because of
-   * alignment issues, stack_size might erroneously appear to be of a
-   * different size.  Fortunately, this is not a critical operation.
-   */
-
-  if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
-    {
-      /* Yes.. Release the old stack */
-
-      up_release_stack(tcb, ttype);
-    }
-
-  /* Do we need to allocate a new stack? */
-
-  if (!tcb->stack_alloc_ptr)
-    {
-      /* Allocate the stack.  If DEBUG is enabled (but not stack debug),
-       * then create a zeroed stack to make stack dumps easier to trace.
-       * If TLS is enabled, then we must allocate aligned stacks.
-       */
-
-#ifdef CONFIG_TLS_ALIGNED
-#ifdef CONFIG_MM_KERNEL_HEAP
-      /* Use the kernel allocator if this is a kernel thread */
-
-      if (ttype == TCB_FLAG_TTYPE_KERNEL)
-        {
-          tcb->stack_alloc_ptr = kmm_memalign(TLS_STACK_ALIGN, stack_size);
-        }
-      else
-#endif
-        {
-          /* Use the user-space allocator if this is a task or pthread */
-
-          tcb->stack_alloc_ptr = kumm_memalign(TLS_STACK_ALIGN, stack_size);
-        }
-
-#else /* CONFIG_TLS_ALIGNED */
-#ifdef CONFIG_MM_KERNEL_HEAP
-      /* Use the kernel allocator if this is a kernel thread */
-
-      if (ttype == TCB_FLAG_TTYPE_KERNEL)
-        {
-          tcb->stack_alloc_ptr = kmm_malloc(stack_size);
-        }
-      else
-#endif
-        {
-          /* Use the user-space allocator if this is a task or pthread */
-
-          tcb->stack_alloc_ptr = kumm_malloc(stack_size);
-        }
-#endif /* CONFIG_TLS_ALIGNED */
-
-#ifdef CONFIG_DEBUG_FEATURES
-      /* Was the allocation successful? */
-
-      if (!tcb->stack_alloc_ptr)
-        {
-          serr("ERROR: Failed to allocate stack, size %d\n", stack_size);
-        }
-#endif
-    }
-
-  /* Did we successfully allocate a stack? */
-
-  if (tcb->stack_alloc_ptr)
-    {
-      /* Yes.. If stack debug is enabled, then fill the stack with a
-       * recognizable value that we can use later to test for high
-       * water marks.
-       */
-
-#ifdef CONFIG_STACK_COLORATION
-      memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
-#endif
-
-      /* Save the adjusted stack values in the struct tcb_s */
-
-      tcb->stack_base_ptr = tcb->stack_alloc_ptr;
-      tcb->adj_stack_size = stack_size;
-      tcb->flags |= TCB_FLAG_FREE_STACK;
-
-#if defined(ARCH_HAVE_LEDS)
-      board_autoled_on(LED_STACKCREATED);
-#endif
-      return OK;
-    }
-
-  return ERROR;
-}
diff --git a/arch/avr/src/avr/up_doirq.c b/arch/avr/src/avr/up_doirq.c
deleted file mode 100644
index ce412ea104..0000000000
--- a/arch/avr/src/avr/up_doirq.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_doirq.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <assert.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <nuttx/board.h>
-#include <arch/board/board.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-uint8_t *up_doirq(uint8_t irq, uint8_t *regs)
-{
-  board_autoled_on(LED_INIRQ);
-#ifdef CONFIG_SUPPRESS_INTERRUPTS
-  PANIC();
-#else
-  uint8_t *savestate;
-
-  /* Nested interrupts are not supported in this implementation.  If you want
-   * to implement nested interrupts, you would have to (1) change the way
-   * that g_current_regs is handled and (2) the design associated with
-   * CONFIG_ARCH_INTERRUPTSTACK.  The savestate variable will not work for
-   * that purpose as implemented here because only the outermost nested
-   * interrupt can result in a context switch (it can probably be deleted).
-   */
-
-  /* Current regs non-zero indicates that we are processing an interrupt;
-   * g_current_regs is also used to manage interrupt level context switches.
-   */
-
-  savestate    = (uint8_t *)g_current_regs;   /* Cast removes volatile attribute */
-  g_current_regs = regs;
-
-  /* Deliver the IRQ */
-
-  irq_dispatch((int)irq, (uint32_t *)regs);
-
-  /* If a context switch occurred while processing the interrupt then
-   * g_current_regs may have change value.  If we return any value different
-   * from the input regs, then the lower level will know that a context
-   * switch occurred during interrupt processing.
-   */
-
-  regs = (uint8_t *)g_current_regs;   /* Cast removes volatile attribute */
-
-  /* Restore the previous value of g_current_regs.  NULL would indicate that
-   * we are no longer in an interrupt handler.  It will be non-NULL if we
-   * are returning from a nested interrupt.
-   */
-
-  g_current_regs = savestate;
-#endif
-  board_autoled_off(LED_INIRQ);
-  return regs;
-}
diff --git a/arch/avr/src/avr/up_dumpstate.c b/arch/avr/src/avr/up_dumpstate.c
deleted file mode 100644
index 542da5c611..0000000000
--- a/arch/avr/src/avr/up_dumpstate.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_dumpstate.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <nuttx/syslog/syslog.h>
-#include <arch/board/board.h>
-
-#include "sched/sched.h"
-#include "up_internal.h"
-
-#ifdef CONFIG_ARCH_STACKDUMP
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: avr_stackdump
- ****************************************************************************/
-
-static void avr_stackdump(uint16_t sp, uint16_t stack_top)
-{
-  uint16_t stack;
-
-  /* Flush any buffered SYSLOG data to avoid overwrite */
-
-  syslog_flush();
-
-  for (stack = sp & ~0x7; stack < (stack_top & ~0x7); stack += 8)
-    {
-      uint8_t *ptr = (uint8_t *)stack;
-      _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x\n",
-             stack, ptr[0], ptr[1], ptr[2], ptr[3],
-             ptr[4], ptr[5], ptr[6], ptr[7]);
-    }
-}
-
-/****************************************************************************
- * Name: avr_registerdump
- ****************************************************************************/
-
-static inline void avr_registerdump(void)
-{
-  /* Are user registers available from interrupt processing? */
-
-  if (g_current_regs)
-    {
-      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
-             0,
-             g_current_regs[REG_R0],  g_current_regs[REG_R1],
-             g_current_regs[REG_R2],  g_current_regs[REG_R3],
-             g_current_regs[REG_R4],  g_current_regs[REG_R5],
-             g_current_regs[REG_R6],  g_current_regs[REG_R7]);
-
-      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
-             8,
-             g_current_regs[REG_R8],  g_current_regs[REG_R9],
-             g_current_regs[REG_R10], g_current_regs[REG_R11],
-             g_current_regs[REG_R12], g_current_regs[REG_R13],
-             g_current_regs[REG_R14], g_current_regs[REG_R15]);
-
-      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
-             16,
-             g_current_regs[REG_R16], g_current_regs[REG_R17],
-             g_current_regs[REG_R18], g_current_regs[REG_R19],
-             g_current_regs[REG_R20], g_current_regs[REG_R21],
-             g_current_regs[REG_R22], g_current_regs[REG_R23]);
-
-      _alert("R%02d: %02x %02x %02x %02x %02x %02x %02x %02x\n",
-             24,
-             g_current_regs[REG_R24], g_current_regs[REG_R25],
-             g_current_regs[REG_R26], g_current_regs[REG_R27],
-             g_current_regs[REG_R28], g_current_regs[REG_R29],
-             g_current_regs[REG_R30], g_current_regs[REG_R31]);
-
-#if !defined(REG_PC2)
-      _alert("PC:  %02x%02x  SP: %02x%02x SREG: %02x\n",
-             g_current_regs[REG_PC0], g_current_regs[REG_PC1],
-             g_current_regs[REG_SPH], g_current_regs[REG_SPL],
-             g_current_regs[REG_SREG]);
-#else
-      _alert("PC:  %02x%02x%02x  SP: %02x%02x SREG: %02x\n",
-             g_current_regs[REG_PC0], g_current_regs[REG_PC1],
-             g_current_regs[REG_PC2], g_current_regs[REG_SPH],
-             g_current_regs[REG_SPL], g_current_regs[REG_SREG]);
-#endif
-    }
-}
-
-/****************************************************************************
- * Name: _up_assert
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_dumpstate
- ****************************************************************************/
-
-void up_dumpstate(void)
-{
-  FAR struct tcb_s *rtcb = running_task();
-  uint16_t sp = up_getsp();
-  uint16_t ustackbase;
-  uint16_t ustacksize;
-#if CONFIG_ARCH_INTERRUPTSTACK > 0
-  uint16_t istackbase;
-  uint16_t istacksize;
-#endif
-
-  /* Dump the registers (if available) */
-
-  avr_registerdump();
-
-  /* Get the limits on the user stack memory */
-
-  ustackbase = (uint16_t)rtcb->stack_base_ptr;
-  ustacksize = (uint16_t)rtcb->adj_stack_size;
-
-  /* Get the limits on the interrupt stack memory */
-
-#if CONFIG_ARCH_INTERRUPTSTACK > 0
-  istackbase = (uint16_t)g_intstackalloc;
-  istacksize = CONFIG_ARCH_INTERRUPTSTACK;
-
-  /* Show interrupt stack info */
-
-  _alert("sp:     %04x\n", sp);
-  _alert("IRQ stack:\n");
-  _alert("  base: %04x\n", istackbase);
-  _alert("  size: %04x\n", istacksize);
-#ifdef CONFIG_STACK_COLORATION
-  _alert("  used: %08x\n", up_check_intstack());
-#endif
-
-  /* Does the current stack pointer lie within the interrupt
-   * stack?
-   */
-
-  if (sp >= istackbase && sp < istackbase + istacksize)
-    {
-      /* Yes.. dump the interrupt stack */
-
-      avr_stackdump(sp, istackbase + istacksize);
-    }
-  else if (g_current_regs)
-    {
-      _alert("ERROR: Stack pointer is not within the interrupt stack\n");
-      avr_stackdump(istackbase, istackbase + istacksize);
-    }
-
-  /* Extract the user stack pointer if we are in an interrupt handler.
-   * If we are not in an interrupt handler.  Then sp is the user stack
-   * pointer (and the above range check should have failed).
-   */
-
-  if (g_current_regs)
-    {
-      sp = g_current_regs[REG_R13];
-      _alert("sp:     %04x\n", sp);
-    }
-
-  _alert("User stack:\n");
-  _alert("  base: %04x\n", ustackbase);
-  _alert("  size: %04x\n", ustacksize);
-#ifdef CONFIG_STACK_COLORATION
-  _alert("  used: %08x\n", up_check_tcbstack(rtcb));
-#endif
-#else
-  _alert("sp:         %04x\n", sp);
-  _alert("stack base: %04x\n", ustackbase);
-  _alert("stack size: %04x\n", ustacksize);
-#ifdef CONFIG_STACK_COLORATION
-  _alert("stack used: %08x\n", up_check_tcbstack(rtcb));
-#endif
-#endif
-
-  /* Dump the user stack if the stack pointer lies within the allocated user
-   * stack memory.
-   */
-
-  if (sp >= ustackbase && sp < ustackbase + ustacksize)
-    {
-      avr_stackdump(sp, ustackbase + ustacksize);
-    }
-  else
-    {
-      _alert("ERROR: Stack pointer is not within allocated stack\n");
-      avr_stackdump(ustackbase, ustackbase + ustacksize);
-    }
-}
-
-#endif /* CONFIG_ARCH_STACKDUMP */
diff --git a/arch/avr/src/avr/up_initialstate.c b/arch/avr/src/avr/up_initialstate.c
deleted file mode 100644
index 84de3f0837..0000000000
--- a/arch/avr/src/avr/up_initialstate.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_initialstate.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <nuttx/arch.h>
-#include <arch/irq.h>
-#include <avr/io.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_initial_state
- *
- * Description:
- *   A new thread is being started and a new TCB has been created. This
- *   function is called to initialize the processor specific portions of the
- *   new TCB.
- *
- *   This function must setup the initial architecture registers and/or stack
- *   so that execution will begin at tcb->start  on the next context switch.
- *
- ****************************************************************************/
-
-void up_initial_state(struct tcb_s *tcb)
-{
-  struct xcptcontext *xcp = &tcb->xcp;
-  uintptr_t sp;
-
-  /* Initialize the idle thread stack */
-
-  if (tcb->pid == IDLE_PROCESS_ID)
-    {
-      char *stack_ptr = (char *)(g_idle_topstack -
-                                 CONFIG_IDLETHREAD_STACKSIZE);
-#ifdef CONFIG_STACK_COLORATION
-      char *stack_end = (char *)avr_getsp();
-
-      /* If stack debug is enabled, then fill the stack with a
-       * recognizable value that we can use later to test for high
-       * water marks.
-       */
-
-      while (stack_ptr < stack_end)
-        {
-          *--stack_end = STACK_COLOR;
-        }
-#endif /* CONFIG_STACK_COLORATION */
-
-      tcb->stack_alloc_ptr = stack_ptr;
-      tcb->stack_base_ptr  = stack_ptr;
-      tcb->adj_stack_size  = CONFIG_IDLETHREAD_STACKSIZE;
-    }
-
-  /* Initialize the initial exception register context structure.  Zeroing
-   * all registers is a good debug helper, but should not be necessary.
-   */
-
-  memset(xcp, 0, sizeof(struct xcptcontext));
-
-  /* Set the initial stack pointer to the top of the allocated stack */
-
-  sp                   = (uintptr_t)tcb->stack_base_ptr +
-                                    tcb->adj_stack_size;
-  xcp->regs[REG_SPH]   = (uint8_t)(sp >> 8);
-  xcp->regs[REG_SPL]   = (uint8_t)(sp & 0xff);
-
-  /* Save the task entry point */
-
-#if !defined(REG_PC2)
-  xcp->regs[REG_PC0]   = (uint8_t)((uintptr_t)tcb->start >> 8);
-  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
-#else
-  xcp->regs[REG_PC0]   = (uint8_t)((uint32_t)(uintptr_t)tcb->start >> 16);
-  xcp->regs[REG_PC1]   = (uint8_t)((uintptr_t)tcb->start >> 8);
-  xcp->regs[REG_PC2]   = (uint8_t)((uintptr_t)tcb->start & 0xff);
-#endif
-
-  /* Enable or disable interrupts, based on user configuration */
-
-#ifdef CONFIG_SUPPRESS_INTERRUPTS
-  xcp->regs[REG_SREG]  = getsreg() & ~(1 << SREG_I);
-#else
-  xcp->regs[REG_SREG]  = getsreg() | (1 << SREG_I);
-#endif
-}
diff --git a/arch/avr/src/avr/up_irq.c b/arch/avr/src/avr/up_irq.c
deleted file mode 100644
index eac64ba8e6..0000000000
--- a/arch/avr/src/avr/up_irq.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_irq.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <arch/irq.h>
-#include <avr/io.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_irqinitialize
- ****************************************************************************/
-
-void up_irqinitialize(void)
-{
-  /* Initialize GPIO interrupt facilities */
-
-#ifdef CONFIG_AVR32_GPIOIRQ
-#ifdef CONFIG_HAVE_WEAKFUNCTIONS
-  if (gpio_irqinitialize != NULL)
-#endif
-    {
-      gpio_irqinitialize();
-    }
-#endif
-
-  /* And finally, enable interrupts */
-
-#ifndef CONFIG_SUPPRESS_INTERRUPTS
-  up_irq_restore(getsreg() | (1 << SREG_I));
-#endif
-}
diff --git a/arch/avr/src/avr/up_releasepending.c b/arch/avr/src/avr/up_releasepending.c
deleted file mode 100644
index 10e47b17ec..0000000000
--- a/arch/avr/src/avr/up_releasepending.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_releasepending.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sched.h>
-#include <debug.h>
-#include <nuttx/arch.h>
-#include <nuttx/sched.h>
-
-#include "sched/sched.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_release_pending
- *
- * Description:
- *   Release and ready-to-run tasks that have
- *   collected in the pending task list.  This can call a
- *   context switch if a new task is placed at the head of
- *   the ready to run list.
- *
- ****************************************************************************/
-
-void up_release_pending(void)
-{
-  struct tcb_s *rtcb = this_task();
-
-  sinfo("From TCB=%p\n", rtcb);
-
-  /* Merge the g_pendingtasks list into the ready-to-run task list */
-
-  if (nxsched_merge_pending())
-    {
-      /* The currently active task has changed!  We will need to switch
-       * contexts.
-       */
-
-      /* Update scheduler parameters */
-
-      nxsched_suspend_scheduler(rtcb);
-
-      if (g_current_regs)
-        {
-          /* Yes, then we have to do things differently.
-           * Just copy the g_current_regs into the OLD rtcb.
-           */
-
-           up_savestate(rtcb->xcp.regs);
-
-          /* Restore the exception context of the rtcb at the (new) head
-           * of the ready-to-run task list.
-           */
-
-          rtcb = this_task();
-
-          /* Update scheduler parameters */
-
-          nxsched_resume_scheduler(rtcb);
-
-          /* Then switch contexts */
-
-          up_restorestate(rtcb->xcp.regs);
-        }
-
-      /* No, then we will need to perform the user context switch */
-
-      else
-        {
-          struct tcb_s *nexttcb = this_task();
-
-          /* Update scheduler parameters */
-
-          nxsched_resume_scheduler(nexttcb);
-
-          /* Switch context to the context of the task at the head of the
-           * ready to run list.
-           */
-
-          up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
-
-          /* up_switchcontext forces a context switch to the task at the
-           * head of the ready-to-run list.  It does not 'return' in the
-           * normal sense.  When it does return, it is because the blocked
-           * task is again ready to run and has execution priority.
-           */
-        }
-    }
-}
diff --git a/arch/avr/src/avr/up_romgetc.c b/arch/avr/src/avr/up_romgetc.c
deleted file mode 100644
index 8304c9efa8..0000000000
--- a/arch/avr/src/avr/up_romgetc.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_romgetc.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <nuttx/arch.h>
-#include <avr/pgmspace.h>
-
-#ifdef CONFIG_ARCH_ROMGETC
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_romgetc
- *
- * Description:
- *   In Harvard architectures, data accesses and instruction accesses occur
- *   on different buses, perhaps concurrently.  All data accesses are
- *   performed on the data bus unless special  machine instructions are
- *   used to read data from the instruction address space.  Also, in the
- *   typical MCU, the available SRAM data memory is much smaller that the
- *   non-volatile FLASH instruction memory.  So if the application requires
- *   many constant strings, the only practical solution may be to store
- *   those constant strings in FLASH memory where they can only be accessed
- *   using architecture-specific machine instructions.
- *
- *   A similar case is where strings are retained in "external" memory such
- *   as EEPROM or serial FLASH.  This case is similar only in that again
- *   special operations are required to obtain the string data; it cannot
- *   be accessed directly from a string pointer.
- *
- *   If CONFIG_ARCH_ROMGETC is defined, then the architecture logic must
- *   export the function up_romgetc().  up_romgetc() will simply read one
- *   byte of data from the instruction space.
- *
- *   If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected: (1)
- *   All format strings in printf, fprintf, sprintf, etc. are assumed to
- *   lie in FLASH (string arguments for %s are still assumed to reside in
- *   SRAM). And (2), the string argument to puts and fputs is assumed to
- *   reside in FLASH.  Clearly, these assumptions may have to modified for
- *   the particular needs of your environment.
- *   There is no "one-size-fits-all" solution for this problem.
- *
- * Additional AVR Assumptions:
- *
- * - This version of up_romgetc obtains string data from FLASH memory.
- * - Since the passed pointer is 16-bits, the strings must lie in the first
- *   64Kb of FLASH.
- *
- ****************************************************************************/
-
-char up_romgetc(FAR const char *ptr)
-{
-  return pgm_read_byte_near(ptr);
-}
-#endif
diff --git a/arch/avr/src/avr/up_schedulesigaction.c b/arch/avr/src/avr/up_schedulesigaction.c
deleted file mode 100644
index 28556bdb47..0000000000
--- a/arch/avr/src/avr/up_schedulesigaction.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_schedulesigaction.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <sched.h>
-#include <debug.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <avr/io.h>
-
-#include "sched/sched.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_schedule_sigaction
- *
- * Description:
- *   This function is called by the OS when one or more
- *   signal handling actions have been queued for execution.
- *   The architecture specific code must configure things so
- *   that the 'sigdeliver' callback is executed on the thread
- *   specified by 'tcb' as soon as possible.
- *
- *   This function may be called from interrupt handling logic.
- *
- *   This operation should not cause the task to be unblocked
- *   nor should it cause any immediate execution of sigdeliver.
- *   Typically, a few cases need to be considered:
- *
- *   (1) This function may be called from an interrupt handler
- *       During interrupt processing, all xcptcontext structures
- *       should be valid for all tasks.  That structure should
- *       be modified to invoke sigdeliver() either on return
- *       from (this) interrupt or on some subsequent context
- *       switch to the recipient task.
- *   (2) If not in an interrupt handler and the tcb is NOT
- *       the currently executing task, then again just modify
- *       the saved xcptcontext structure for the recipient
- *       task so it will invoke sigdeliver when that task is
- *       later resumed.
- *   (3) If not in an interrupt handler and the tcb IS the
- *       currently executing task -- just call the signal
- *       handler now.
- *
- * Assumptions:
- *   Called from critical section
- *
- ****************************************************************************/
-
-void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
-{
-  uintptr_t reg_ptr = (uintptr_t)up_sigdeliver;
-
-  sinfo("tcb=%p sigdeliver=%p\n", tcb, sigdeliver);
-
-  /* Refuse to handle nested signal actions */
-
-  if (!tcb->xcp.sigdeliver)
-    {
-      /* First, handle some special cases when the signal is
-       * being delivered to the currently executing task.
-       */
-
-      sinfo("rtcb=%p g_current_regs=%p\n",
-            this_task(), g_current_regs);
-
-      if (tcb == this_task())
-        {
-          /* CASE 1:  We are not in an interrupt handler and
-           * a task is signalling itself for some reason.
-           */
-
-          if (!g_current_regs)
-            {
-              /* In this case just deliver the signal now. */
-
-              sigdeliver(tcb);
-            }
-
-          /* CASE 2:  We are in an interrupt handler AND the
-           * interrupted task is the same as the one that
-           * must receive the signal, then we will have to modify
-           * the return state as well as the state in the TCB.
-           *
-           * Hmmm... there looks like a latent bug here: The following
-           * logic would fail in the strange case where we are in an
-           * interrupt handler, the thread is signalling itself, but
-           * a context switch to another task has occurred so that
-           * g_current_regs does not refer to the thread of this_task()!
-           */
-
-          else
-            {
-              /* Save registers that must be protected while the signal
-               * handler runs. These will be restored by the signal
-               * trampoline after the signal(s) have been delivered.
-               */
-
-              tcb->xcp.sigdeliver   = sigdeliver;
-              tcb->xcp.saved_pc0    = g_current_regs[REG_PC0];
-              tcb->xcp.saved_pc1    = g_current_regs[REG_PC1];
-#if defined(REG_PC2)
-              tcb->xcp.saved_pc2    = g_current_regs[REG_PC2];
-#endif
-              tcb->xcp.saved_sreg   = g_current_regs[REG_SREG];
-
-              /* Then set up to vector to the trampoline with interrupts
-               * disabled
-               */
-
-#if !defined(REG_PC2)
-              g_current_regs[REG_PC0] = (uint16_t)reg_ptr >> 8;
-              g_current_regs[REG_PC1] = (uint16_t)reg_ptr & 0xff;
-#else
-              g_current_regs[REG_PC0] = (uint32_t)reg_ptr >> 16;
-              g_current_regs[REG_PC1] = (uint32_t)reg_ptr >> 8;
-              g_current_regs[REG_PC2] = (uint32_t)reg_ptr & 0xff;
-#endif
-              g_current_regs[REG_SREG] &= ~(1 << SREG_I);
-
-              /* And make sure that the saved context in the TCB
-               * is the same as the interrupt return context.
-               */
-
-              up_savestate(tcb->xcp.regs);
-            }
-        }
-
-      /* Otherwise, we are (1) signaling a task is not running
-       * from an interrupt handler or (2) we are not in an
-       * interrupt handler and the running task is signalling
-       * some non-running task.
-       */
-
-      else
-        {
-          /* Save registers that must be protected while the signal handler
-           * runs. These will be restored by the signal trampoline after
-           * the signals have been delivered.
-           */
-
-          tcb->xcp.sigdeliver       = sigdeliver;
-          tcb->xcp.saved_pc0        = tcb->xcp.regs[REG_PC0];
-          tcb->xcp.saved_pc1        = tcb->xcp.regs[REG_PC1];
-#if defined(REG_PC2)
-          tcb->xcp.saved_pc2        = tcb->xcp.regs[REG_PC2];
-#endif
-          tcb->xcp.saved_sreg       = tcb->xcp.regs[REG_SREG];
-
-          /* Then set up to vector to the trampoline with interrupts
-           * disabled
-           */
-
-#if !defined(REG_PC2)
-          tcb->xcp.regs[REG_PC0]    = (uint16_t)reg_ptr >> 8;
-          tcb->xcp.regs[REG_PC1]    = (uint16_t)reg_ptr & 0xff;
-#else
-          tcb->xcp.regs[REG_PC0]    = (uint32_t)reg_ptr >> 16;
-          tcb->xcp.regs[REG_PC1]    = (uint32_t)reg_ptr >> 8;
-          tcb->xcp.regs[REG_PC2]    = (uint32_t)reg_ptr & 0xff;
-
-#endif
-          tcb->xcp.regs[REG_SREG]  &= ~(1 << SREG_I);
-        }
-    }
-}
diff --git a/arch/avr/src/avr/up_sigdeliver.c b/arch/avr/src/avr/up_sigdeliver.c
deleted file mode 100644
index 36d6c456e7..0000000000
--- a/arch/avr/src/avr/up_sigdeliver.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_sigdeliver.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <nuttx/board.h>
-#include <arch/board/board.h>
-
-#include "sched/sched.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_sigdeliver
- *
- * Description:
- *   This is the a signal handling trampoline.  When a signal action was
- *   posted.  The task context was mucked with and forced to branch to this
- *   location with interrupts disabled.
- *
- ****************************************************************************/
-
-void up_sigdeliver(void)
-{
-  struct tcb_s *rtcb = this_task();
-  uint8_t regs[XCPTCONTEXT_REGS];
-
-  board_autoled_on(LED_SIGNAL);
-
-  sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
-        rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head);
-  DEBUGASSERT(rtcb->xcp.sigdeliver != NULL);
-
-  /* Save the return state on the stack. */
-
-  up_copystate(regs, rtcb->xcp.regs);
-
-#ifndef CONFIG_SUPPRESS_INTERRUPTS
-  /* Then make sure that interrupts are enabled.  Signal handlers must always
-   * run with interrupts enabled.
-   */
-
-  up_irq_enable();
-#endif
-
-  /* Deliver the signal */
-
-  ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
-
-  /* Output any debug messages BEFORE restoring errno (because they may
-   * alter errno), then disable interrupts again and restore the original
-   * errno that is needed by the user logic (it is probably EINTR).
-   */
-
-  sinfo("Resuming\n");
-  up_irq_save();
-
-  /* Modify the saved return state with the actual saved values in the
-   * TCB.  This depends on the fact that nested signal handling is
-   * not supported.  Therefore, these values will persist throughout the
-   * signal handling action.
-   *
-   * Keeping this data in the TCB resolves a security problem in protected
-   * and kernel mode:  The regs[] array is visible on the user stack and
-   * could be modified by a hostile program.
-   */
-
-  regs[REG_PC0]        = rtcb->xcp.saved_pc0;
-  regs[REG_PC1]        = rtcb->xcp.saved_pc1;
-#if defined(REG_PC2)
-  regs[REG_PC2]        = rtcb->xcp.saved_pc2;
-#endif
-  regs[REG_SREG]       = rtcb->xcp.saved_sreg;
-  rtcb->xcp.sigdeliver = NULL;  /* Allows next handler to be scheduled */
-
-  /* Then restore the correct state for this thread of execution. This is an
-   * unusual case that must be handled by up_fullcontextresore. This case is
-   * unusual in two ways:
-   *
-   *   1. It is not a context switch between threads.  Rather,
-   *      up_fullcontextrestore must behave more it more like a longjmp
-   *      within the same task, using the same stack.
-   *   2. In this case, up_fullcontextrestore is called with r12 pointing to
-   *      a register save area on the stack to be destroyed.  This is
-   *      dangerous because there is the very real possibility that the new
-   *      stack pointer might overlap with the register save area and that
-   *      stack usage in up_fullcontextrestore might corrupt the register
-   *      save data before the state is restored.  At present, there does
-   *      not appear to be any stack overlap problems.  If there were, then
-   *      adding 3 words to the size of register save structure size will
-   *      protect its contents.
-   */
-
-  board_autoled_off(LED_SIGNAL);
-  up_fullcontextrestore(regs);
-}
diff --git a/arch/avr/src/avr/up_spi.c b/arch/avr/src/avr/up_spi.c
deleted file mode 100644
index 55b50b4c59..0000000000
--- a/arch/avr/src/avr/up_spi.c
+++ /dev/null
@@ -1,488 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_spi.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <arch/board/board.h>
-#include <nuttx/irq.h>
-#include <nuttx/arch.h>
-#include <nuttx/mutex.h>
-#include <nuttx/spi/spi.h>
-
-#include <avr/io.h>
-#include <avr/power.h>
-
-#include "up_internal.h"
-#include "chip.h"
-#include "avr.h"
-
-#ifdef CONFIG_AVR_SPI
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-struct avr_spidev_s
-{
-  struct spi_dev_s spidev;     /* Externally visible part of the SPI interface */
-  mutex_t          lock;       /* Held while chip is selected for mutual exclusion */
-  uint32_t         frequency;  /* Requested clock frequency */
-  uint32_t         actual;     /* Actual clock frequency */
-  uint8_t          mode;       /* Mode 0,1,2,3 */
-};
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/* SPI methods */
-
-static int      spi_lock(FAR struct spi_dev_s *dev, bool lock);
-static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
-                                 uint32_t frequency);
-static void     spi_setmode(FAR struct spi_dev_s *dev,
-                            enum spi_mode_e mode);
-static void     spi_setbits(FAR struct spi_dev_s *dev, int nbits);
-static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
-static void     spi_sndblock(FAR struct spi_dev_s *dev,
-                             FAR const void *buffer, size_t nwords);
-static void     spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer,
-                              size_t nwords);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static const struct spi_ops_s g_spiops =
-{
-  .lock              = spi_lock,
-  .select            = avr_spiselect,
-  .setfrequency      = spi_setfrequency,
-  .setmode           = spi_setmode,
-  .setbits           = spi_setbits,
-#ifdef CONFIG_SPI_HWFEATURES
-  .hwfeatures        = 0,                 /* Not supported */
-#endif
-  .status            = avr_spistatus,
-#ifdef CONFIG_SPI_CMDDATA
-  .cmddata           = avr_spicmddata,
-#endif
-  .send              = spi_send,
-  .sndblock          = spi_sndblock,
-  .recvblock         = spi_recvblock,
-  .registercallback  = 0,                 /* Not implemented */
-};
-
-static struct avr_spidev_s g_spidev =
-{
-  .spidev            =
-  {
-    .ops             = &g_spiops,
-  },
-  .lock              = NXMUTEX_INITIALIZER,
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: spi_lock
- *
- * Description:
- *   On SPI buses where there are multiple devices, it will be necessary to
- *   lock SPI to have exclusive access to the buses for a sequence of
- *   transfers.  The bus should be locked before the chip is selected. After
- *   locking the SPI bus, the caller should then also call the setfrequency,
- *   setbits, and setmode methods to make sure that the SPI is properly
- *   configured for the device.  If the SPI bus is being shared, then it
- *   may have been left in an incompatible state.
- *
- * Input Parameters:
- *   dev  - Device-specific state data
- *   lock - true: Lock spi bus, false: unlock SPI bus
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
-{
-  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
-  int ret;
-
-  if (lock)
-    {
-      ret = nxmutex_lock(&priv->lock);
-    }
-  else
-    {
-      ret = nxmutex_unlock(&priv->lock);
-    }
-
-  return ret;
-}
-
-/****************************************************************************
- * Name: spi_setfrequency
- *
- * Description:
- *   Set the SPI frequency.
- *
- * Input Parameters:
- *   dev -       Device-specific state data
- *   frequency - The SPI frequency requested
- *
- * Returned Value:
- *   Returns the actual frequency selected
- *
- ****************************************************************************/
-
-static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
-                                 uint32_t frequency)
-{
-  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
-  uint32_t actual;
-
-  /* TODO: This is missing the actual logic to update the frequency.
-   * The divider bits are computed but not actually used.
-   */
-
-  /* Has the request frequency changed? */
-
-  if (frequency != priv->frequency)
-    {
-      /* Read the SPI status and control registers, clearing all div bits */
-
-      uint8_t spcr = SPCR & ~((1 << SPR0) | (1 << SPR1));
-      uint8_t spsr = SPSR & ~(1 << SPI2X);
-
-      /* Select the best divider bits */
-
-      if (frequency >= BOARD_CPU_CLOCK / 2)
-        {
-          spsr  |= (1 << SPI2X);
-          actual = BOARD_CPU_CLOCK / 2;
-        }
-      else if (frequency >= BOARD_CPU_CLOCK / 4)
-        {
-          actual = BOARD_CPU_CLOCK / 4;
-        }
-      else if (frequency >= BOARD_CPU_CLOCK / 8)
-        {
-          spcr  |= (1 << SPR0);
-          spsr  |= (1 << SPI2X);
-          actual = BOARD_CPU_CLOCK / 8;
-        }
-      else if (frequency >= BOARD_CPU_CLOCK / 16)
-        {
-          spcr  |= (1 << SPR0);
-          actual = BOARD_CPU_CLOCK / 16;
-        }
-      else if (frequency >= BOARD_CPU_CLOCK / 32)
-        {
-          spcr  |= (1 << SPR1);
-          spsr  |= (1 << SPI2X);
-          actual = BOARD_CPU_CLOCK / 32;
-        }
-      else if (frequency >= BOARD_CPU_CLOCK / 64)
-        {
-          spcr  |= (1 << SPR1);
-          actual = BOARD_CPU_CLOCK / 64;
-        }
-      else /* if (frequency >= BOARD_CPU_CLOCK / 128) */
-        {
-          spcr  |= (1 << SPR0) | (1 << SPR1);
-          actual = BOARD_CPU_CLOCK / 128;
-        }
-
-      /* Save the frequency setting */
-
-      priv->frequency = frequency;
-      priv->actual    = actual;
-    }
-  else
-    {
-      actual          = priv->actual;
-    }
-
-  spiinfo("Frequency %" PRId32 "->%" PRId32 "\n", frequency, actual);
-  return actual;
-}
-
-/****************************************************************************
- * Name: spi_setmode
- *
- * Description:
- *   Set the SPI mode. Optional.  See enum spi_mode_e for mode definitions
- *
- * Input Parameters:
- *   dev -  Device-specific state data
- *   mode - The SPI mode requested
- *
- * Returned Value:
- *   none
- *
- ****************************************************************************/
-
-static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode)
-{
-  FAR struct avr_spidev_s *priv = (FAR struct avr_spidev_s *)dev;
-
-  /* Has the mode changed? */
-
-  if (mode != priv->mode)
-    {
-      uint8_t regval;
-
-      /* Yes... Set SPI CR appropriately */
-
-      regval = SPCR;
-      regval &= ~((1 << CPOL) | (1 << CPHA));
-
-      switch (mode)
-        {
-        case SPIDEV_MODE0: /* CPOL=0; CPHA=0 */
-          break;
-
-        case SPIDEV_MODE1: /* CPOL=0; CPHA=1 */
-          regval |= (1 << CPHA);
-          break;
-
-        case SPIDEV_MODE2: /* CPOL=1; CPHA=0 */
-          regval |= (1 << CPOL);
-          break;
-
-        case SPIDEV_MODE3: /* CPOL=1; CPHA=1 */
-          regval |= ((1 << CPOL) | (1 << CPHA));
-          break;
-
-        default:
-          DEBUGASSERT(FALSE);
-          return;
-        }
-
-      SPSR = regval;
-
-      /* Save the mode so that subsequent re-configurations will be faster */
-
-      priv->mode = mode;
-    }
-}
-
-/****************************************************************************
- * Name: spi_setbits
- *
- * Description:
- *   Set the number if bits per word.
- *
- * Input Parameters:
- *   dev -  Device-specific state data
- *   nbits - The number of bits requested (only nbits == 8 is supported)
- *
- * Returned Value:
- *   none
- *
- ****************************************************************************/
-
-static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
-{
-  DEBUGASSERT(dev && nbits == 8);
-}
-
-/****************************************************************************
- * Name: spi_send
- *
- * Description:
- *   Exchange one word on SPI
- *
- * Input Parameters:
- *   dev - Device-specific state data
- *   wd  - The word to send.  the size of the data is determined by the
- *         number of bits selected for the SPI interface.
- *
- * Returned Value:
- *   response
- *
- ****************************************************************************/
-
-static uint32_t spi_send(FAR struct spi_dev_s *dev, uint32_t wd)
-{
-  /* Write the data to transmitted to the SPI Data Register */
-
-  SPDR = (uint8_t)wd;
-
-  /* Wait for transmission to complete */
-
-  while (!(SPSR & (1 << SPIF)));
-
-  /* Then return the received value */
-
-  return (uint32_t)SPDR;
-}
-
-/****************************************************************************
- * Name: spi_sndblock
- *
- * Description:
- *   Send a block of data on SPI
- *
- * Input Parameters:
- *   dev -    Device-specific state data
- *   buffer - A pointer to the buffer of data to be sent
- *   nwords - the length of data to send from the buffer in number of words.
- *            The wordsize is determined by the number of bits-per-word
- *            selected for the SPI interface.  If nbits <= 8, the data is
- *            packed into uint8_t's; if nbits >8, the data is packed into
- *            uint16_t's
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer,
-                         size_t nwords)
-{
-  FAR uint8_t *ptr = (FAR uint8_t *)buffer;
-
-  spiinfo("nwords: %d\n", nwords);
-  while (nwords-- > 0)
-    {
-      spi_send(dev, (uint16_t)*ptr++);
-    }
-}
-
-/****************************************************************************
- * Name: spi_recvblock
- *
- * Description:
- *   Revice a block of data from SPI
- *
- * Input Parameters:
- *   dev -    Device-specific state data
- *   buffer - A pointer to the buffer in which to receive data
- *   nwords - the length of data that can be received in the buffer in number
- *            of words.  The wordsize is determined by the number of bits-
- *            per-wordselected for the SPI interface.  If nbits <= 8, the
- *            data is packed into uint8_t's; if nbits >8, the data is packed
- *            into uint16_t's
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer,
-                          size_t nwords)
-{
-  FAR uint8_t *ptr = (FAR uint8_t *)buffer;
-
-  spiinfo("nwords: %d\n", nwords);
-  while (nwords-- > 0)
-    {
-      *ptr++ = spi_send(dev, (uint16_t)0xff);
-    }
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: avr_spibus_initialize
- *
- * Description:
- *   Initialize the selected SPI port
- *
- * Input Parameters:
- *   Port number (for hardware that has multiple SPI interfaces)
- *
- * Returned Value:
- *   Valid SPI device structure reference on success; a NULL on failure
- *
- ****************************************************************************/
-
-FAR struct spi_dev_s *avr_spibus_initialize(int port)
-{
-  FAR struct avr_spidev_s *priv = &g_spidev;
-  irqstate_t flags;
-  uint8_t regval;
-
-  /* Make sure that clocks are provided to the SPI module */
-
-  flags = enter_critical_section();
-  power_spi_enable();
-
-  /* Set MOSI and SCK as outputs, all others are inputs (default on reset):
-   *
-   * PB3: PDO/MISO/PCINT3
-   * PB2: PDI/MOSI/PCINT2
-   * PB1: SCK/PCINT1
-   * PB0: SS/PCINT0
-   */
-
-  DDRB |= (1 << 2) | (1 << 1);
-
-  /* - Enable SPI
-   * - Set Master
-   * - Set clock rate oscillator/4
-   * - Set CPOL for SPI clock mode 0
-   */
-
-  SPCR = (1 << SPE) | (1 << MSTR);
-
-  /* Set clock rate to f(osc)/8 */
-
-  /* SPSR |= (1 << 0); */
-
-  /* Clear status flags by reading them */
-
-  regval = SPSR;
-  UNUSED(regval);
-  regval = SPDR;
-  UNUSED(regval);
-
-  /* Set the initial SPI configuration */
-
-  priv->frequency = 0;
-  priv->mode      = SPIDEV_MODE0;
-
-  /* Select a default frequency of approx. 400KHz */
-
-  spi_setfrequency((FAR struct spi_dev_s *)priv, 400000);
-
-  leave_critical_section(flags);
-  return &priv->spidev;
-}
-#endif /* CONFIG_AVR_SPI */
diff --git a/arch/avr/src/avr/up_stackframe.c b/arch/avr/src/avr/up_stackframe.c
deleted file mode 100644
index e279daccd8..0000000000
--- a/arch/avr/src/avr/up_stackframe.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_stackframe.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <sched.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <arch/irq.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_stack_frame
- *
- * Description:
- *   Allocate a stack frame in the TCB's stack to hold thread-specific data.
- *   This function may be called anytime after up_create_stack() or
- *   up_use_stack() have been called but before the task has been started.
- *
- *   Thread data may be kept in the stack (instead of in the TCB) if it is
- *   accessed by the user code directly.  This includes such things as
- *   argv[].  The stack memory is guaranteed to be in the same protection
- *   domain as the thread.
- *
- *   The following TCB fields will be re-initialized:
- *
- *   - adj_stack_size: Stack size after removal of the stack frame from
- *     the stack
- *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
- *     Arguments has been removed from the stack allocation.
- *
- * Input Parameters:
- *   - tcb:  The TCB of new task
- *   - frame_size:  The size of the stack frame to allocate.
- *
- *  Returned Value:
- *   - A pointer to bottom of the allocated stack frame.  NULL will be
- *     returned on any failures.  The alignment of the returned value is
- *     the same as the alignment of the stack itself.
- *
- ****************************************************************************/
-
-FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
-{
-  FAR void *ret;
-
-  /* Is there already a stack allocated? Is it big enough? */
-
-  if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
-    {
-      return NULL;
-    }
-
-  ret = tcb->stack_base_ptr;
-  memset(ret, 0, frame_size);
-
-  /* Save the adjusted stack values in the struct tcb_s */
-
-  tcb->stack_base_ptr  = (FAR uint8_t *)tcb->stack_base_ptr + frame_size;
-  tcb->adj_stack_size -= frame_size;
-
-  /* And return the pointer to the allocated region */
-
-  return ret;
-}
diff --git a/arch/avr/src/avr/up_switchcontext.S b/arch/avr/src/avr/up_switchcontext.S
deleted file mode 100644
index de7676dcee..0000000000
--- a/arch/avr/src/avr/up_switchcontext.S
+++ /dev/null
@@ -1,123 +0,0 @@
-/************************************************************************************
- * arch/avr/src/avr/up_switchcontext.S
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ************************************************************************************/
-
-/************************************************************************************
- * Included Files
- ************************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <arch/irq.h>
-
-#include "excptmacros.h"
-
-/************************************************************************************
- * Pre-processor Definitions
- ************************************************************************************/
-
-/************************************************************************************
- * Public Symbols
- ************************************************************************************/
-
-	.file		"up_switchcontext.S"
-
-/************************************************************************************
- * Macros
- ************************************************************************************/
-
-/************************************************************************************
- * Public Functions
- ************************************************************************************/
-
-/************************************************************************************
- * Name: up_switchcontext
- *
- * Description:
- *   Save the current thread context and restore the specified context.  The full
- *   C function prototype is:
- *
- *   void up_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
- *
- * On Entry:
- *   r24-r25: savregs
- *   r22-r23: restoreregs
- *
- * Returned Value:
- *   up_switchcontext forces a context switch to the task "canned" in restoreregs.
- *   It does not 'return' in the normal sense, rather, it will context switch back
- *   to the function point.  When it does 'return,' it is because the blocked
- *   task hat was "pickeled" in the saveregs "can" is again ready to run and has
- *   execution priority.
- *
- * Assumptions:
- *   global interrupts disabled by the caller.
- *
- ************************************************************************************/
-
-	.text
-	.globl	up_switchcontext
-	.func	up_switchcontext
-up_switchcontext:
-	/* Use X [r26:r27] to reference the save structure.  (X is Call-used) */
-
-	movw	r26, r24
-
-	/* Save the context to saveregs */
-
-	USER_SAVE
-
-	/* Then fall through to do the full context restore with r24-r5 = restoreregs */
-
-	movw	r24, r22
-	.endfunc
-
-/****************************************************************************
- * Name: up_fullcontextrestore
- *
- * Description:
- *   Restore the full-running context of a thread.
- *
- * Input Parameters:
- *   r24-r25 = A pointer to the register save area of the thread to be restored.
- *
- * C Prototype:
- *  void up_fullcontextrestore(uint8_t *regs);
- *
- * Assumptions:
- *   Interrupts are disabled.
- *
- ****************************************************************************/
-
-	.text
-	.global	up_fullcontextrestore
-	.func	up_fullcontextrestore
-up_fullcontextrestore:
-	/* Use X [r26:r27] to reference the restore structure.  */
-
-	movw	r26, r24
-
-	/* Restore the context from the TCB saved registers */
-
-	TCB_RESTORE
-
-	/* Returning from the function is handled in TCB_RESTORE */
-
-	.endfunc
-	.end
diff --git a/arch/avr/src/avr/up_unblocktask.c b/arch/avr/src/avr/up_unblocktask.c
deleted file mode 100644
index 1d906bb4b8..0000000000
--- a/arch/avr/src/avr/up_unblocktask.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_unblocktask.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-#include <nuttx/arch.h>
-#include <nuttx/sched.h>
-
-#include "sched/sched.h"
-#include "clock/clock.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_unblock_task
- *
- * Description:
- *   A task is currently in the ready-to-run list but has been prepped
- *   to execute. Restore its context, and start execution.
- *
- * Input Parameters:
- *   tcb: Refers to the head task of the ready-to-run list
- *     which will be executed.
- *   rtcb: Refers to the running task which will be blocked.
- *
- ****************************************************************************/
-
-void up_unblock_task(struct tcb_s *tcb, struct tcb_s *rtcb)
-{
-  /* Update scheduler parameters */
-
-  nxsched_suspend_scheduler(rtcb);
-
-  /* Are we in an interrupt handler? */
-
-  if (g_current_regs)
-    {
-      /* Yes, then we have to do things differently.
-       * Just copy the g_current_regs into the OLD rtcb.
-       */
-
-      up_savestate(rtcb->xcp.regs);
-
-      /* Update scheduler parameters */
-
-      nxsched_resume_scheduler(tcb);
-
-      /* Then switch contexts */
-
-      up_restorestate(tcb->xcp.regs);
-    }
-
-  /* No, then we will need to perform the user context switch */
-
-  else
-    {
-      /* Update scheduler parameters */
-
-      nxsched_resume_scheduler(tcb);
-
-      /* Switch context to the context of the task at the head of the
-       * ready to run list.
-       */
-
-      up_switchcontext(rtcb->xcp.regs, tcb->xcp.regs);
-
-      /* up_switchcontext forces a context switch to the task at the
-       * head of the ready-to-run list.  It does not 'return' in the
-       * normal sense.  When it does return, it is because the blocked
-       * task is again ready to run and has execution priority.
-       */
-    }
-}
diff --git a/arch/avr/src/avr/up_usestack.c b/arch/avr/src/avr/up_usestack.c
deleted file mode 100644
index 1ab016b840..0000000000
--- a/arch/avr/src/avr/up_usestack.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr/up_usestack.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/arch.h>
-#include <nuttx/tls.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_use_stack
- *
- * Description:
- *   Setup up stack-related information in the TCB using pre-allocated stack
- *   memory.  This function is called only from nxtask_init() when a task or
- *   kernel thread is started (never for pthreads).
- *
- *   The following TCB fields must be initialized:
- *
- *   - adj_stack_size: Stack size after adjustment for hardware,
- *     processor, etc.  This value is retained only for debug
- *     purposes.
- *   - stack_alloc_ptr: Pointer to allocated stack
- *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
- *     Arguments has been removed from the stack allocation.
- *
- * Input Parameters:
- *   - tcb: The TCB of new task
- *   - stack_size:  The allocated stack size.
- *
- *   NOTE:  Unlike up_stack_create() and up_stack_release, this function
- *   does not require the task type (ttype) parameter.  The TCB flags will
- *   always be set to provide the task type to up_use_stack() if it needs
- *   that information.
- *
- ****************************************************************************/
-
-int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
-{
-#ifdef CONFIG_TLS_ALIGNED
-  /* Make certain that the user provided stack is properly aligned */
-
-  DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
-#endif
-
-  /* Is there already a stack allocated? */
-
-  if (tcb->stack_alloc_ptr)
-    {
-      /* Yes.. Release the old stack allocation */
-
-      up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
-    }
-
-  /* Save the new stack allocation */
-
-  tcb->stack_alloc_ptr = stack;
-
-  /* If stack debug is enabled, then fill the stack with a recognizable value
-   * that we can use later to test for high water marks.
-   */
-
-#ifdef CONFIG_STACK_COLORATION
-  memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
-#endif
-
-  /* The AVR uses a push-down stack:  the stack grows toward loweraddresses
-   * in memory.  The stack pointer register, points to the lowest, valid work
-   * address (the "top" of the stack).  Items on the stack are referenced as
-   * positive word offsets from sp.
-   */
-
-  /* Save the adjusted stack values in the struct tcb_s */
-
-  tcb->stack_base_ptr = tcb->stack_alloc_ptr;
-  tcb->adj_stack_size = stack_size;
-
-  return OK;
-}
diff --git a/arch/avr/src/avr32/avr32.h b/arch/avr/src/avr32/avr32.h
index b61cde415e..d32c2c55c2 100644
--- a/arch/avr/src/avr32/avr32.h
+++ b/arch/avr/src/avr32/avr32.h
@@ -53,8 +53,8 @@
  * state from the TCB.
  */
 
-#define up_savestate(regs)    up_copystate(regs, (uint32_t*)g_current_regs)
-#define up_restorestate(regs) (g_current_regs = regs)
+#define avr_savestate(regs)     avr_copystate(regs, (uint32_t*)g_current_regs)
+#define avr_restorestate(regs)  (g_current_regs = regs)
 
 /****************************************************************************
  * Public Types
@@ -85,7 +85,7 @@ extern uint32_t g_idle_topstack;
 #ifndef __ASSEMBLY__
 
 /****************************************************************************
- * Name:  up_copystate
+ * Name:  avr_copystate
  *
  * Description:
  *   Copy the contents of a register state save structure from one location
@@ -93,37 +93,37 @@ extern uint32_t g_idle_topstack;
  *
  ****************************************************************************/
 
-void up_copystate(uint32_t *dest, uint32_t *src);
+void avr_copystate(uint32_t *dest, uint32_t *src);
 
 /****************************************************************************
- * Name:  up_fullcontextrestore
+ * Name:  avr_fullcontextrestore
  *
  * Description:
  *   Restore the full context of a saved thread/task.
  *
  ****************************************************************************/
 
-void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function;
+void avr_fullcontextrestore(uint32_t *restoreregs) noreturn_function;
 
 /****************************************************************************
- * Name:  up_switchcontext
+ * Name:  avr_switchcontext
  *
  * Description:
  *   Switch from one thread/task context to another.
  *
  ****************************************************************************/
 
-void up_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
+void avr_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
 
 /****************************************************************************
- * Name:  up_doirq
+ * Name:  avr_doirq
  *
  * Description:
  *   Dispatch an interrupt.
  *
  ****************************************************************************/
 
-uint32_t *up_doirq(int irq, uint32_t *regs);
+uint32_t *avr_doirq(int irq, uint32_t *regs);
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ARCH_AVR_SRC_AVR32_AVR32_H */
diff --git a/arch/avr/src/avr32/avr_blocktask.c b/arch/avr/src/avr32/avr_blocktask.c
new file mode 100644
index 0000000000..8ce9585a68
--- /dev/null
+++ b/arch/avr/src/avr32/avr_blocktask.c
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_blocktask.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "group/group.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_block_task
+ *
+ * Description:
+ *   The currently executing task has already removed from ready-to-run list.
+ *   Save its context and switch to the next running task at the head of the
+ *   ready-to-run list.
+ *
+ * Input Parameters:
+ *   rtcb: Reference to the running task which is different to the
+ *     task (next running task) at the head of the list.
+ *
+ ****************************************************************************/
+
+void up_block_task(struct tcb_s *rtcb)
+{
+  /* Update scheduler parameters */
+
+  nxsched_suspend_scheduler(rtcb);
+
+  /* Are we in an interrupt handler? */
+
+  if (g_current_regs)
+    {
+      /* Yes, then we have to do things differently.
+       * Just copy the g_current_regs into the OLD rtcb.
+       */
+
+      avr_savestate(rtcb->xcp.regs);
+
+      /* Restore the exception context of the rtcb at the (new) head
+       * of the ready-to-run task list.
+       */
+
+      rtcb = this_task();
+
+      /* Reset scheduler parameters */
+
+      nxsched_resume_scheduler(rtcb);
+
+      /* Then switch contexts.  Any new address environment needed by
+       * the new thread will be instantiated before the return from
+       * interrupt.
+       */
+
+      avr_restorestate(rtcb->xcp.regs);
+    }
+
+  /* No, then we will need to perform the user context switch */
+
+  else
+    {
+      /* Get the context of the task at the head of the ready to
+       * run list.
+       */
+
+      struct tcb_s *nexttcb = this_task();
+
+#ifdef CONFIG_ARCH_ADDRENV
+      /* Make sure that the address environment for the previously
+       * running task is closed down gracefully (data caches dump,
+       * MMU flushed) and set up the address environment for the new
+       * thread at the head of the ready-to-run list.
+       */
+
+      group_addrenv(nexttcb);
+#endif
+      /* Reset scheduler parameters */
+
+      nxsched_resume_scheduler(nexttcb);
+
+      /* Then switch contexts */
+
+      avr_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
+
+      /* avr_switchcontext forces a context switch to the task at the
+       * head of the ready-to-run list.  It does not 'return' in the
+       * normal sense.  When it does return, it is because the blocked
+       * task is again ready to run and has execution priority.
+       */
+    }
+}
diff --git a/arch/avr/src/avr32/avr_copystate.c b/arch/avr/src/avr32/avr_copystate.c
new file mode 100644
index 0000000000..58963040ec
--- /dev/null
+++ b/arch/avr/src/avr32/avr_copystate.c
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_copystate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+#include <arch/avr32/irq.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_copystate
+ ****************************************************************************/
+
+/* A little faster than most memcpy's */
+
+void avr_copystate(uint32_t *dest, uint32_t *src)
+{
+  int i;
+
+  /* The state is copied from the stack to the TCB, but only a reference is
+   * passed to get the state from the TCB.  So the following check avoids
+   * copying the TCB save area onto itself:
+   */
+
+  if (src != dest)
+    {
+      for (i = 0; i < XCPTCONTEXT_REGS; i++)
+        {
+          *dest++ = *src++;
+        }
+    }
+}
diff --git a/arch/avr/src/avr32/avr_createstack.c b/arch/avr/src/avr32/avr_createstack.c
new file mode 100644
index 0000000000..ae265d8ac0
--- /dev/null
+++ b/arch/avr/src/avr32/avr_createstack.c
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_createstack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ *   Allocate a stack for a new thread and setup up stack-related information
+ *   in the TCB.
+ *
+ *   The following TCB fields must be initialized by this function:
+ *
+ *   - adj_stack_size: Stack size after adjustment for hardware, processor,
+ *     etc.  This value is retained only for debug purposes.
+ *   - stack_alloc_ptr: Pointer to allocated stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb: The TCB of new task
+ *   - stack_size:  The requested stack size.  At least this much
+ *     must be allocated.
+ *   - ttype:  The thread type.  This may be one of following (defined in
+ *     include/nuttx/sched.h):
+ *
+ *       TCB_FLAG_TTYPE_TASK     Normal user task
+ *       TCB_FLAG_TTYPE_PTHREAD  User pthread
+ *       TCB_FLAG_TTYPE_KERNEL   Kernel thread
+ *
+ *     This thread type is normally available in the flags field of the TCB,
+ *     however, there are certain contexts where the TCB may not be fully
+ *     initialized when up_create_stack is called.
+ *
+ *     If CONFIG_BUILD_KERNEL is defined, then this thread type may affect
+ *     how the stack is allocated.  For example, kernel thread stacks should
+ *     be allocated from protected kernel memory.  Stacks for user tasks and
+ *     threads must come from memory that is accessible to user code.
+ *
+ ****************************************************************************/
+
+int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
+{
+#ifdef CONFIG_TLS_ALIGNED
+  /* The allocated stack size must not exceed the maximum possible for the
+   * TLS feature.
+   */
+
+  DEBUGASSERT(stack_size <= TLS_MAXSTACK);
+  if (stack_size >= TLS_MAXSTACK)
+    {
+      stack_size = TLS_MAXSTACK;
+    }
+#endif
+
+  /* Is there already a stack allocated of a different size?  Because of
+   * alignment issues, stack_size might erroneously appear to be of a
+   * different size.  Fortunately, this is not a critical operation.
+   */
+
+  if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
+    {
+      /* Yes.. Release the old stack */
+
+      up_release_stack(tcb, ttype);
+    }
+
+  /* Do we need to allocate a new stack? */
+
+  if (!tcb->stack_alloc_ptr)
+    {
+      /* Allocate the stack.  If DEBUG is enabled (but not stack debug),
+       * then create a zeroed stack to make stack dumps easier to trace.
+       * If TLS is enabled, then we must allocate aligned stacks.
+       */
+
+#ifdef CONFIG_TLS_ALIGNED
+#ifdef CONFIG_MM_KERNEL_HEAP
+      /* Use the kernel allocator if this is a kernel thread */
+
+      if (ttype == TCB_FLAG_TTYPE_KERNEL)
+        {
+          tcb->stack_alloc_ptr = kmm_memalign(TLS_STACK_ALIGN, stack_size);
+        }
+      else
+#endif
+        {
+          /* Use the user-space allocator if this is a task or pthread */
+
+          tcb->stack_alloc_ptr = kumm_memalign(TLS_STACK_ALIGN, stack_size);
+        }
+
+#else /* CONFIG_TLS_ALIGNED */
+#ifdef CONFIG_MM_KERNEL_HEAP
+      /* Use the kernel allocator if this is a kernel thread */
+
+      if (ttype == TCB_FLAG_TTYPE_KERNEL)
+        {
+          tcb->stack_alloc_ptr = kmm_malloc(stack_size);
+        }
+      else
+#endif
+        {
+          /* Use the user-space allocator if this is a task or pthread */
+
+          tcb->stack_alloc_ptr = kumm_malloc(stack_size);
+        }
+#endif /* CONFIG_TLS_ALIGNED */
+
+#ifdef CONFIG_DEBUG_FEATURES
+      /* Was the allocation successful? */
+
+      if (!tcb->stack_alloc_ptr)
+        {
+          serr("ERROR: Failed to allocate stack, size %d\n", stack_size);
+        }
+#endif
+    }
+
+  /* Did we successfully allocate a stack? */
+
+  if (tcb->stack_alloc_ptr)
+    {
+      uintptr_t top_of_stack;
+      size_t size_of_stack;
+
+      /* Yes.. If stack debug is enabled, then fill the stack with a
+       * recognizable value that we can use later to test for high
+       * water marks.
+       */
+
+#ifdef CONFIG_STACK_COLORATION
+      memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
+#endif
+
+      /* The AVR32 uses a push-down stack:  the stack grows toward lower
+       * addresses in memory.  The stack pointer register, points to the
+       * lowest, valid work address (the "top" of the stack).  Items on
+       * the stack are referenced as positive word offsets from sp.
+       */
+
+      top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
+
+      /* The AVR32 stack must be aligned at word (4 byte) boundaries. If
+       * necessary top_of_stack must be rounded down to the next boundary
+       */
+
+      top_of_stack &= ~3;
+      size_of_stack = top_of_stack - (uintptr_t)tcb->stack_alloc_ptr;
+
+      /* Save the adjusted stack values in the struct tcb_s */
+
+      tcb->stack_base_ptr = tcb->stack_alloc_ptr;
+      tcb->adj_stack_size = size_of_stack;
+      tcb->flags |= TCB_FLAG_FREE_STACK;
+
+      board_autoled_on(LED_STACKCREATED);
+      return OK;
+    }
+
+  return ERROR;
+}
diff --git a/arch/avr/src/avr32/avr_doirq.c b/arch/avr/src/avr32/avr_doirq.c
new file mode 100644
index 0000000000..8268c9f2bd
--- /dev/null
+++ b/arch/avr/src/avr32/avr_doirq.c
@@ -0,0 +1,121 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_doirq.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <assert.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "avr_internal.h"
+#include "group/group.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+uint32_t *avr_doirq(int irq, uint32_t *regs)
+{
+  board_autoled_on(LED_INIRQ);
+#ifdef CONFIG_SUPPRESS_INTERRUPTS
+  PANIC();
+#else
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * g_current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported.
+   */
+
+  DEBUGASSERT(g_current_regs == NULL);
+  g_current_regs = regs;
+
+  /* Deliver the IRQ */
+
+  irq_dispatch(irq, regs);
+
+#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
+  /* Check for a context switch.  If a context switch occurred, then
+   * g_current_regs will have a different value than it did on entry.
+   * If an interrupt level context switch has occurred, then restore
+   * the floating point state and the establish the correct address
+   * environment before returning from the interrupt.
+   */
+
+  if (regs != g_current_regs)
+    {
+#ifdef CONFIG_ARCH_FPU
+      /* Restore floating point registers */
+
+      up_restorefpu((uint32_t *)g_current_regs);
+#endif
+
+#ifdef CONFIG_ARCH_ADDRENV
+      /* Make sure that the address environment for the previously
+       * running task is closed down gracefully (data caches dump,
+       * MMU flushed) and set up the address environment for the new
+       * thread at the head of the ready-to-run list.
+       */
+
+      group_addrenv(NULL);
+#endif
+    }
+#endif
+
+  /* If a context switch occurred while processing the interrupt then
+   * g_current_regs may have change value.  If we return any value different
+   * from the input regs, then the lower level will know that a context
+   * switch occurred during interrupt processing.
+   */
+
+  regs = g_current_regs;
+
+  /* Set g_current_regs to NULL to indicate that we are no longer in
+   * an interrupt handler.
+   */
+
+  g_current_regs = NULL;
+#endif
+  board_autoled_off(LED_INIRQ);
+  return regs;
+}
diff --git a/arch/avr/src/avr32/avr_dumpstate.c b/arch/avr/src/avr32/avr_dumpstate.c
new file mode 100644
index 0000000000..b422733cf5
--- /dev/null
+++ b/arch/avr/src/avr32/avr_dumpstate.c
@@ -0,0 +1,191 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_dumpstate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/syslog/syslog.h>
+#include <arch/board/board.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+#ifdef CONFIG_ARCH_STACKDUMP
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_stackdump
+ ****************************************************************************/
+
+static void avr_stackdump(uint32_t sp, uint32_t stack_top)
+{
+  uint32_t stack;
+
+  /* Flush any buffered SYSLOG data to avoid overwrite */
+
+  syslog_flush();
+
+  for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
+    {
+      uint32_t *ptr = (uint32_t *)stack;
+      _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
+             stack, ptr[0], ptr[1], ptr[2], ptr[3],
+             ptr[4], ptr[5], ptr[6], ptr[7]);
+    }
+}
+
+/****************************************************************************
+ * Name: avr_registerdump
+ ****************************************************************************/
+
+static inline void avr_registerdump(void)
+{
+  /* Are user registers available from interrupt processing? */
+
+  if (g_current_regs)
+    {
+      _alert("R%d: %08x %08x %08x %08x %08x %08x %08x %08x\n",
+             0,
+             g_current_regs[REG_R0], g_current_regs[REG_R1],
+             g_current_regs[REG_R2], g_current_regs[REG_R3],
+             g_current_regs[REG_R4], g_current_regs[REG_R5],
+             g_current_regs[REG_R6], g_current_regs[REG_R7]);
+
+      _alert("R%d: %08x %08x %08x %08x %08x %08x %08x %08x\n",
+             8,
+             g_current_regs[REG_R8],  g_current_regs[REG_R9],
+             g_current_regs[REG_R10], g_current_regs[REG_R11],
+             g_current_regs[REG_R12], g_current_regs[REG_R13],
+             g_current_regs[REG_R14], g_current_regs[REG_R15]);
+
+      _alert("SR: %08x\n", g_current_regs[REG_SR]);
+    }
+}
+
+/****************************************************************************
+ * Name: avr_dumpstate
+ ****************************************************************************/
+
+void avr_dumpstate(void)
+{
+  FAR struct tcb_s *rtcb = running_task();
+  uint32_t sp = up_getsp();
+  uint32_t ustackbase;
+  uint32_t ustacksize;
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+  uint32_t istackbase;
+  uint32_t istacksize;
+#endif
+
+  /* Dump the registers (if available) */
+
+  avr_registerdump();
+
+  /* Get the limits on the user stack memory */
+
+  ustackbase = (uint32_t)rtcb->stack_base_ptr;
+  ustacksize = (uint32_t)rtcb->adj_stack_size;
+
+  /* Get the limits on the interrupt stack memory */
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+  istackbase = (uint32_t)g_intstackalloc;
+  istacksize = (CONFIG_ARCH_INTERRUPTSTACK & ~3);
+
+  /* Show interrupt stack info */
+
+  _alert("sp:     %08x\n", sp);
+  _alert("IRQ stack:\n");
+  _alert("  base: %08x\n", istackbase);
+  _alert("  size: %08x\n", istacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("  used: %08x\n", up_check_intstack());
+#endif
+
+  /* Does the current stack pointer lie within the interrupt
+   * stack?
+   */
+
+  if (sp >= istackbase && sp < istackbase + istacksize)
+    {
+      /* Yes.. dump the interrupt stack */
+
+      avr_stackdump(sp, istackbase + istacksize);
+    }
+  else if (g_current_regs)
+    {
+      _alert("ERROR: Stack pointer is not within the interrupt stack\n");
+      avr_stackdump(istackbase, istackbase + istacksize);
+    }
+
+  /* Extract the user stack pointer if we are in an interrupt handler.
+   * If we are not in an interrupt handler.  Then sp is the user stack
+   * pointer (and the above range check should have failed).
+   */
+
+  if (g_current_regs)
+    {
+      sp = g_current_regs[REG_R13];
+      _alert("sp:     %08x\n", sp);
+    }
+
+  _alert("User stack:\n");
+  _alert("  base: %08x\n", ustackbase);
+  _alert("  size: %08x\n", ustacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("  used: %08x\n", up_check_tcbstack(rtcb));
+#endif
+#else
+  _alert("sp:         %08x\n", sp);
+  _alert("stack base: %08x\n", ustackbase);
+  _alert("stack size: %08x\n", ustacksize);
+#ifdef CONFIG_STACK_COLORATION
+  _alert("stack used: %08x\n", up_check_tcbstack(rtcb));
+#endif
+#endif
+
+  /* Dump the user stack if the stack pointer lies within the allocated user
+   * stack memory.
+   */
+
+  if (sp >= ustackbase && sp < ustackbase + ustacksize)
+    {
+      avr_stackdump(sp, ustackbase + ustacksize);
+    }
+  else
+    {
+      _alert("ERROR: Stack pointer is not within allocated stack\n");
+      avr_stackdump(ustackbase, ustackbase + ustacksize);
+    }
+}
+#endif
diff --git a/arch/avr/src/avr32/avr_exceptions.S b/arch/avr/src/avr32/avr_exceptions.S
new file mode 100644
index 0000000000..192f2a4952
--- /dev/null
+++ b/arch/avr/src/avr32/avr_exceptions.S
@@ -0,0 +1,359 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_exceptions.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <arch/avr32/avr32.h>
+#include <arch/irq.h>
+
+/****************************************************************************
+ * External Symbols
+ ****************************************************************************/
+
+	.global		avr32_int0irqno			/* Returns IRQ number of INT0 event */
+	.global		avr32_int1irqno			/* Returns IRQ number of INT1 event */
+	.global		avr32_int2irqno			/* Returns IRQ number of INT2 event */
+	.global		avr32_int3irqno			/* Returns IRQ number of INT3 event */
+	.global		avr_doirq				/* Dispatch an IRQ                  */
+	.global		avr_fullcontextrestore	/* Restore new task context         */
+
+/****************************************************************************
+ * Macros
+ ****************************************************************************/
+
+/* Exception entry logic.  On entry, the context save area looks like:      */
+/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx SR PC                   */
+/*                                                  ^     ^+2*4             */
+/* Upon joining common logic, the context save are will look like:          */
+/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx 10 SR PC                   */
+/*                                               ^        ^+3*4             */
+/* and r10 will hold the exception's IRQ number                             */
+
+	.macro  HANDLER, label, irqno
+\label:
+	st.w	--sp, r10
+	mov		r10, \irqno
+	rjmp	avr32_xcptcommon	/* FIXME!!! Need IRQ in a register */
+	.endm
+
+/****************************************************************************
+ * Exception Vector Table
+ ****************************************************************************/
+
+/* The Exception Vector Base Address (EVBA) register will contain "a        */
+/* pointer to the exception routines. All exception routines start at this  */
+/* address, or at a defined offset relative to the address. Special         */
+/* alignment requirements may apply for EVBA, depending on the              */
+/* implementation of the interrupt controller."                             */
+
+/* REVISIT:  This alignment requirement may be different on other AVR32s    */
+
+	.text
+	.balign 0x200
+
+	.global	vectortab
+	.type	vectortab, @function
+vectortab:
+	lda.w	pc, avr32_unrec			/* EVBA+0x00 Unrecoverable exception    */
+	lda.w	pc, avr32_tlbmult		/* EVBA+0x04 TLB multiple hit           */
+	lda.w	pc, avr32_busdata		/* EVBA+0x08 Bus error data fetch       */
+	lda.w	pc, avr32_businst		/* EVBA+0x0c Bus error instr fetch      */
+	lda.w	pc, avr32_nmi			/* EVBA+0x10 NMI                        */
+	lda.w	pc, avr32_instaddr		/* EVBA+0x14 Instruction Address        */
+	lda.w	pc, avr32_itlbrot		/* EVBA+0x18 ITLB Protection            */
+	lda.w	pc, avr32_bp			/* EVBA+0x1c Breakpoint                 */
+	lda.w	pc, avr32_invinst		/* EVBA+0x20 Illegal Opcode             */
+	lda.w	pc, avr32_unimpinst		/* EVBA+0x24 Unimplemented instruction  */
+	lda.w	pc, avr32_priv			/* EVBA+0x28 Privilege violation        */
+	lda.w	pc, avr32_fp			/* EVBA+0x2c Floating-point             */
+	lda.w	pc, avr32_cop			/* EVBA+0x30 Coprocessor absent         */
+	lda.w	pc, avr32_rddata		/* EVBA+0x34 Data Address (Read)        */
+	lda.w	pc, avr32_wrdata		/* EVBA+0x38 Data Address (Write)       */
+	lda.w	pc, avr32_tddtlbprot	/* EVBA+0x3c DTLB Protection (Read)     */
+	lda.w	pc, avr32_wrdtlbprot	/* EVBA+0x40 DTLB Protection (Write)    */
+	lda.w	pc, avr32_dltbmod		/* EVBA+0x44 DTLB Modified              */
+	.rept	2
+	lda.w	pc,	avr32_badvector		/* EVBA+0x48-0x4c No such vector        */
+	.endr
+	lda.w	pc, avr32_itlbmiss		/* EVBA+0x50 ITLB Miss                  */
+	.rept	3
+	lda.w	pc,	avr32_badvector		/* EVBA+0x54-0x5c No such vector        */
+	.endr
+	lda.w	pc, avr32_rddtlb		/* EVBA+0x60 DTLB Miss (Read)           */
+	.rept	3
+	lda.w	pc,	avr32_badvector		/* EVBA+0x64-0x6c No such vector        */
+	.endr
+	lda.w	pc, avr32_wrdtlb		/* EVBA+0x70 DTLB Miss (Write)          */
+	.rept	(3+4*8)
+	lda.w	pc,	avr32_badvector		/* EVBA+0x74-0xfc No such vector        */
+	.endr
+	lda.w	pc, avr32_super			/* EVBA+0x100 Supervisor call           */
+
+/****************************************************************************
+ * Interrupts
+ ****************************************************************************/
+
+/* The interrupt controller must provide an address that is relative to     */
+/* the EVBA so it is natural to define these interrupt vectors just after   */
+/* the exception table. On entry to each interrupt handler, R8-R12, LR, PC  */
+/* and SR have already been pushed onto the system stack by the MCU.        */
+/*                                                                          */
+/* An interrupt may disappear while it is being fetched by the CPU and,     */
+/* hence spurious interrupt may result.                                     */
+
+	.balign 4
+	.global	avr32_int0
+avr32_int0:
+	mov		r12, 0				/* r12=interrupt level 0                    */
+	rjmp	avr32_intcommon		/* Jump to common interrupt handling logic  */
+
+	.balign	4
+	.global	avr32_int1
+avr32_int1:
+	mov		r12, 1				/* r12=interrupt level 1                    */
+	rjmp	avr32_intcommon		/* Jump to common interrupt handling logic  */
+
+	.balign	4
+	.global	avr32_int2
+avr32_int2:
+	mov		r12, 2				/* r12=interrupt level 2                    */
+	rjmp	avr32_intcommon		/* Jump to common interrupt handling logic  */
+
+	.balign	4
+	.global	avr32_int3
+avr32_int3:
+	mov		r12, 3				/* r12=interrupt level 3                    */
+
+/* Common interrupt handling logic.  R12 holds the interrupt level index    */
+
+avr32_intcommon:
+	mcall	.Lavr32_intirqno	/* Get the IRQ number of the int0 event     */
+	cp.w	r12, 0				/* Negative returned if spurious interrupt  */
+	brge	avr32_common		/* Jump to the common xcptn handling logic  */
+	rete						/* Ignore spurious interrupt                */
+
+.Lavr32_intirqno:
+	.word	avr32_intirqno
+
+/****************************************************************************
+ * Exception Vector Handlers
+ ****************************************************************************/
+
+/* Exception Handlers:                                                      */
+/* On entry to each, the context save area looks like this:                 */
+/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx SR PC                   */
+/*                                                  ^     ^+2*4             */
+
+	HANDLER	avr32_unrec, AVR32_IRQ_UNREC			/* Unrecoverable xcptn  */
+	HANDLER	avr32_tlbmult, AVR32_IRQ_TLBMULT		/* TLB multiple hit     */
+	HANDLER	avr32_busdata, AVR32_IRQ_BUSDATA		/* Bus error data fetch */
+	HANDLER	avr32_businst, AVR32_IRQ_BUSINST		/* Bus err instr fetch  */
+	HANDLER	avr32_nmi, AVR32_IRQ_NMI				/* NMI                  */
+	HANDLER	avr32_instaddr, AVR32_IRQ_INSTADDR		/* Instruction Address  */
+	HANDLER	avr32_itlbrot, AVR32_IRQ_ITLBPROT		/* ITLB Protection      */
+	HANDLER	avr32_bp, AVR32_IRQ_BP					/* Breakpoint           */
+	HANDLER	avr32_invinst, AVR32_IRQ_INVINST		/* Illegal Opcode       */
+	HANDLER	avr32_unimpinst, AVR32_IRQ_UNIMPINST	/* Unimplemented intsr  */
+	HANDLER	avr32_priv, AVR32_IRQ_PRIV 				/* Privilege violation  */
+	HANDLER	avr32_fp, AVR32_IRQ_FP					/* Floating-point       */
+	HANDLER	avr32_cop, AVR32_IRQ_COP				/* Coprocessor absent   */
+	HANDLER	avr32_rddata, AVR32_IRQ_RDDATA			/* Data Address (RD)    */
+	HANDLER	avr32_wrdata, AVR32_IRQ_WRDATA 			/* Data Address (WR)    */
+	HANDLER	avr32_tddtlbprot, AVR32_IRQ_RDDTLBPROT	/* DTLB Protection (RD) */
+	HANDLER	avr32_wrdtlbprot, AVR32_IRQ_WRDTLBPROT	/* DTLB Protection (WR) */
+	HANDLER	avr32_dltbmod, AVR32_IRQ_DLTBMOD		/* DTLB Modified        */
+	HANDLER	avr32_itlbmiss, AVR32_IRQ_ITLBMISS		/* ITLB Miss            */
+	HANDLER	avr32_rddtlb, AVR32_IRQ_RDDTLB 			/* DTLB Miss (RD)       */
+	HANDLER	avr32_wrdtlb, AVR32_IRQ_WRDTLB			/* DTLB Miss (WR)       */
+	HANDLER	avr32_super, AVR32_IRQ_SUPER			/* Supervisor call      */
+	HANDLER	avr32_badvector, AVR32_IRQ_BADVECTOR	/* No such vector       */
+
+/* Common exception handling logic.  Unlike the interrupt handlers, the     */
+/* exception handlers do not save R8-R12, and LR on the stack.  Only the PC */
+/* and SR have been pushed onto the system stack by the MCU.  The following */
+/* logic creates a common stack frame for exception handlers prior to       */
+/* joining to the common interrupt/exception logic below.                   */
+/*                                                                          */
+/* The context save area looks like this on entry to the HANDLER above.     */
+/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx SR PC                   */
+/*                                                  ^     ^+2*4             */
+/* Upon joining common logic here, the context save are will loke:          */
+/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx 10 SR PC                   */
+/*                                               ^        ^+3*4             */
+/* and r10 will hold the exception's IRQ number                             */
+/*                                                                          */
+/* either (1) non-time-critical, or (2) fatal.  Obvious, that would not be  */
+/* the case if TLB missing handling is required.  Such time-critical vector */
+/* handling should be handled differently.                                  */
+
+avr32_xcptcommon:
+/* Save r10-r12, lr on the stack:                                           */
+/*     xx xx xx xx xx xx xx xx xx xx xx LR 12 11 10 SR PC                   */
+/*                                      ^           ^+4*4 ^+6*4             */
+
+	stm		--sp, r11-r12, lr
+
+/* Move SR and PC into the expected position:                               */
+/*     xx xx xx xx xx xx xx xx xx SR PC LI 12 11 10 SR PC                   */
+/*                                ^                       ^+8*4             */
+
+	ld.w	r12, sp[4*4]
+	ld.w	r11, sp[5*4]
+	stm		--sp, r11-r12
+
+/* Save r8 and r8:                                                          */
+/*     xx xx xx xx xx xx xx xx xx SR PC LI 12 11 10 SR PC                   */
+/*                                ^                 ^+6*4 ^+8*4             */
+
+	st.w	sp[6*4], r9
+	st.w	sp[7*4], r8
+
+/* Move the IRQ number in r12 and fall through to the common event handling */
+/* logic.                                                                   */
+
+	mov		r12, r10
+
+/****************************************************************************
+ * Common Event Handling Logic
+ ****************************************************************************/
+
+/* After this point, logic to manage interrupts and exceptions is           */
+/* equivalent. Here we have:                                                */
+/*                                                                          */
+/*   R8-R12, LR, SR, and the PC on the stack.                               */
+/*   R12 holds the IRQ number to be dispatched.                             */
+/*                                                                          */
+/* The context save area looks like this:                                   */
+/*     xx xx xx xx xx xx xx xx xx SR PC LR 12 11 10 09 08                   */
+/*                                ^                       ^+8*4             */
+/* This function will finish construction of the register save structure    */
+/* and call the IRQ dispatching logic.                                      */
+
+avr32_common:
+    /* Disable interrupts in the current SR.  This is necessary because the */
+	/* AVR32 permits nested interrupts (if they are of higher priority).    */
+	/* We can support nested interrupts without some effort because:        */
+	/* - The global variable g_current_regs permits only one interrupt,     */
+	/* - If CONFIG_ARCH_INTERRUPTSTACK is defined, then there is a single   */
+	/*   interrupt stack, and                                               */
+	/* - Probably other things.                                             */
+
+	ssrf	AVR32_SR_GM_SHIFT
+
+	/* Save the SP (as it was before the interrupt) in the context save     */
+	/* structure.                                                           */
+	/*     xx xx xx xx xx xx xx xx SP SR PC LR 12 11 10 09 08               */
+	/*                             ^sp                                      */
+
+	mov		r8, sp
+	sub		r8, -8*4
+	st.w	--sp, r8
+
+	/* Saving R0-R7 is all that is left to complete the context save.       */
+	/*     07 06 05 04 03 02 01 00 SP SR PC LR 12 11 10 09 08               */
+	/*     ^sp                                                              */
+
+	stm		--sp, r0-r7
+
+	/* Now call avr_doirq passing the IRQ number in r12 and the base address */
+	/* of the register context save area in r11.                            */
+
+	mov		r11, sp
+
+	/* Switch to the interrupt stack if so configured.  Move the current    */
+	/* stack pointer into a preserved register (r7) and set the interrupt   */
+	/* stack pointer.                                                       */
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+	mov		r7, sp
+	lddpc	sp, .Linstacktopptr
+#endif
+
+	/* Call avr_doirq with r12=IRQ number and r11=register save area         */
+
+	mcall	.Ldoirqptr
+
+	/* Restore the user stack pointer.                                      */
+	/*     07 06 05 04 03 02 01 00 SP SR PC LR 12 11 10 09 08               */
+	/*     ^sp                                                              */
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+	mov		sp, r7
+#endif
+
+	/* On return, r12 will hold the new address of the register context     */
+	/* save area.  On an interrupt context switch, this will (1) not be the  */
+	/* same as the value of r12 passed to avr_doirq(), and (2) may not       */
+	/* reside on a stack.                                                   */
+
+	cp.w	sp, r12
+	brne	1f
+
+	/* No context switch... do the simple return.  First, restore r0-r7.    */
+	/*     xx xx xx xx xx xx xx xx SP SR PC LR 12 11 10 09 08               */
+	/*                             ^sp                                      */
+
+	ldm		sp++, r0-r7
+
+	/* Skip over the saved stack pointer and return from the interrupt.     */
+	/*     xx xx xx xx xx xx xx xx xx SR PC LR 12 11 10 09 08               */
+	/*                                ^sp                                   */
+
+	sub		sp, -4
+	rete
+
+	/* Context switch... jump to up_fullcontestrestor with r12=address of   */
+	/* the task context to restore.                                         */
+
+1:
+	lddpc	pc, .Lfullcontextrestoreptr
+
+.Ldoirqptr:
+	.word	avr_doirq
+.Lfullcontextrestoreptr:
+	.word	avr_fullcontextrestore
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+.Linstacktopptr:
+	.word	g_intstacktop
+#endif
+	.size	vectortab, .-vectortab
+
+/************************************************************************************
+ *  Name: up_interruptstack
+ ************************************************************************************/
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+	.bss
+	.align	4
+	.globl	g_intstackalloc
+	.type	g_intstackalloc, object
+	.globl	g_intstacktop
+	.type	g_intstacktop, object
+g_intstackalloc:
+	.skip	(CONFIG_ARCH_INTERRUPTSTACK & ~3)
+g_intstacktop:
+	.size	g_intstackalloc, .-g_intstackalloc
+#endif
+	.end
diff --git a/arch/avr/src/avr32/avr_fullcontextrestore.S b/arch/avr/src/avr32/avr_fullcontextrestore.S
new file mode 100644
index 0000000000..6f97347373
--- /dev/null
+++ b/arch/avr/src/avr32/avr_fullcontextrestore.S
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * arch/avr32/src/avr32/avr_fullcontextrestore.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <arch/avr32/avr32.h>
+
+/****************************************************************************
+ * External Symbols
+ ****************************************************************************/
+
+	.file		"avr_fullcontextrestore.S"
+
+/****************************************************************************
+ * Macros
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_fullcontextrestore
+ *
+ * Description:
+ *   Restore the full-running context of a thread.
+ *
+ *   NOTE: Thus function must handle one very strange case.  That is when
+ *   this function is called with avr_sigdeliver().  That case is strange in
+ *   two ways:
+ *
+ *   1. It is not a context switch between threads.  Rather, avr_fullcontextrestore
+ *      must behave more it more like a longjmp within the same task, using the
+ *      same stack.
+ *   2. In this case, this function is called with r12 pointing to a register
+ *      save area on the stack to be destroyed.  This is dangerous for two
+ *      reasons: (a) there is a period of time where the stack contents still
+ *      contain valid data, but are outside of range protected by the stack
+ *      pointer (hence, interrupts must be disabled), and (b) there is the
+ *      very real possibility that the new stack pointer might overlap with
+ *      the register save area and stack usage in this function might corrupt
+ *      the register save data before the state is restored.  It turns that
+ *      an extra 3 words in the register save structure size will protect its
+ *      contents (because that is the number of temporaries pushed onto the
+ *      stack).
+ *
+ * Input Parameters:
+ *   r12 = A pointer to the register save area of the thread to be restored.
+ *
+ * C Prototype:
+ *  void avr_fullcontextrestore(uint32_t *regs);
+ *
+ * Assumptions:
+ *   Interrupts are disabled.
+ *
+ ****************************************************************************/
+
+	.text
+	.global	avr_fullcontextrestore
+	.type	avr_fullcontextrestore, @function
+avr_fullcontextrestore:
+
+	/* Initially, r12 points to the r7 save area. Restore r0-r7.            */
+	/* regs: 07 06 05 04 03 02 01 00 xx xx xx xx xx xx xx xx xx             */
+	/*                               ^r12                                   */
+
+	ldm 	r12++, r0-r7
+
+    /* Now, r12 points to the SP (r13) save area.  Recover the value of     */
+	/* the stack pointer (r13).  We will need to save some temporaries on   */
+	/* the final stack.                                                     */
+	/* regs: 07 06 05 04 03 02 01 00 SP xx xx xx xx xx xx xx xx             */
+	/*                                  ^r12                                */
+
+	ld.w	sp, r12++
+
+	/* Now r12 points to the SR save area.  Skip over the SR for now.       */
+	/* regs: 07 06 05 04 03 02 01 00 SP xx xx xx xx xx xx xx xx             */
+	/*                                     ^r12                             */
+
+    sub		r12, -1*4
+
+	/* Get the pc, lr, and r12 (in r10, r9, and r8) and move them to the    */
+    /* stack.  We can now use r12 and lr as scratch registers.              */
+	/* regs: 07 06 05 04 03 02 01 00 SP xx PC LR 12 xx xx xx xx             */
+	/*                                              ^r12                    */
+	/* stack: lr, r12, pc                                                   */
+	/*        ^sp                                                           */
+
+	ldm		r12++, r8-r10		/* Get r10=pc, r9=lr, r8=r12                */
+
+#if 0 /* See comments below */
+	stm		--sp, r8-r10		/* Save r12, lr, and pc from the stack      */
+#else
+	st.w	--sp, r10			/* Save R10=PC on the stack                 */
+	st.w	--sp, r8			/* Save R8=r12 on the stack                 */
+	st.w	--sp, r9			/* Save R9=lr on the stack                  */
+#endif
+
+	/* Now r12 now points to the r11 save area.  Restore r8-r11.            */
+	/* regs: 07 06 05 04 03 02 01 00 SP xx PC LR 12 11 10 09 08             */
+	/*                                                          ^r12        */
+
+	ldm		r12++, r8-r11
+
+	/* r12 now points +4 beyond the end of the register save area. Restore  */
+	/* SR.  NOTE:  This may enable interrupts!                              */
+	/* regs: 07 06 05 04 03 02 01 00 SP SR PC LR 12 11 10 09 08             */
+	/*                                  ^r12-4*8                ^r12        */
+
+	ld.w	lr, r12[-4*8]
+	mtsr	AVR32_SR, lr
+
+	/* Restore PC, LR and r12.  Hmmm.. I need to study the behaviour of ldm */
+	/* when r12,lr, and pc on in ldm reglist16.  I'm not sure that I want   */
+	/* that behavior.                                                       */
+	/* stack: lr, r12, pc                                                   */
+	/*        ^sp                                                           */
+
+#if 0
+	ldm		sp++, r12, lr, pc	/* Restore r12, lr, and pc from the stack   */
+#else
+	ld.w	lr, sp++			/* Recover lr from the stack                */
+	ld.w	r12, sp++			/* Recover r12 from the stack               */
+	ld.w	pc, sp++			/* Jump to the address on the stack         */
+#endif
+	.end
diff --git a/arch/avr/src/avr32/avr_initialstate.c b/arch/avr/src/avr32/avr_initialstate.c
new file mode 100644
index 0000000000..fad705ca75
--- /dev/null
+++ b/arch/avr/src/avr32/avr_initialstate.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_initialstate.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/arch.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_initial_state
+ *
+ * Description:
+ *   A new thread is being started and a new TCB has been created. This
+ *   function is called to initialize the processor specific portions of the
+ *   new TCB.
+ *
+ *   This function must setup the initial architecture registers and/or stack
+ *   so that execution will begin at tcb->start  on the next context switch.
+ *
+ ****************************************************************************/
+
+void up_initial_state(struct tcb_s *tcb)
+{
+  struct xcptcontext *xcp = &tcb->xcp;
+
+  /* Initialize the idle thread stack */
+
+  if (tcb->pid == IDLE_PROCESS_ID)
+    {
+      char *stack_ptr = (char *)(g_idle_topstack -
+                                 CONFIG_IDLETHREAD_STACKSIZE);
+#ifdef CONFIG_STACK_COLORATION
+      char *stack_end = (char *)avr_getsp();
+
+      /* If stack debug is enabled, then fill the stack with a
+       * recognizable value that we can use later to test for high
+       * water marks.
+       */
+
+      while (stack_ptr < stack_end)
+        {
+          *--stack_end = STACK_COLOR;
+        }
+#endif /* CONFIG_STACK_COLORATION */
+
+      tcb->stack_alloc_ptr = stack_ptr;
+      tcb->stack_base_ptr  = stack_ptr;
+      tcb->adj_stack_size  = CONFIG_IDLETHREAD_STACKSIZE;
+    }
+
+  /* Initialize the initial exception register context structure.  Zeroing
+   * all registers is a good debug helper, but should not be necessary.
+   */
+
+#ifdef CONFIG_DEBUG_FEATURES
+  memset(xcp, 0, sizeof(struct xcptcontext));
+#else
+  /* No pending signal delivery */
+
+  xcp->sigdeliver   = NULL;
+
+  /* Clear the frame pointer and link register since this is the outermost
+   * frame.
+   */
+
+  xcp->regs[REG_R7] = 0;
+  xcp->regs[REG_LR] = 0;
+#endif
+
+  /* Set the initial stack pointer to the top of the allocated stack */
+
+  xcp->regs[REG_SP]      = (uint32_t)tcb->stack_base_ptr +
+                                     tcb->adj_stack_size;
+
+  /* Save the task entry point */
+
+  xcp->regs[REG_PC]      = (uint32_t)tcb->start;
+
+  /* Set supervisor- or user-mode, depending on how NuttX is configured and
+   * what kind of thread is being started.  Disable FIQs in any event
+   *
+   * If the kernel build is not selected, then all threads run in
+   * supervisor-mode.
+   */
+
+#ifdef CONFIG_BUILD_KERNEL
+#  error "Missing logic for the CONFIG_BUILD_KERNEL build"
+#endif
+
+  /* Enable or disable interrupts, based on user configuration */
+
+#ifdef CONFIG_SUPPRESS_INTERRUPTS
+  xcp->regs[REG_SR]    = avr32_sr() | AVR32_SR_GM_MASK;
+#else
+  xcp->regs[REG_SR]    = avr32_sr() & ~AVR32_SR_GM_MASK;
+#endif
+}
diff --git a/arch/avr/src/avr32/avr_nommuhead.S b/arch/avr/src/avr32/avr_nommuhead.S
new file mode 100644
index 0000000000..3a82338687
--- /dev/null
+++ b/arch/avr/src/avr32/avr_nommuhead.S
@@ -0,0 +1,140 @@
+/****************************************************************************
+ * arch/avr32/src/avr32/avr_nommuhead.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <arch/avr32/avr32.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * External Symbols
+ ****************************************************************************/
+
+	.file		"up_nommuhead.S"
+	.global		_sbss			/* Start of .bss.  Defined by ld.script */
+	.global		_ebss			/* End of .bss.  Defined by ld.script */
+#ifdef CONFIG_BOOT_RUNFROMFLASH
+	.global		_sdata			/* Start of .data section in RAM */
+	.global		_edata			/* End of .data section in RAM */
+	.global		_eronly			/* Start of .data section in FLASH */
+#endif
+	.global		avr_lowinit		/* Perform low level initialization */
+	.global		nx_start		/* NuttX entry point */
+	.global		vectortab		/* Vector base address */
+
+/****************************************************************************
+ * Macros
+ ****************************************************************************/
+
+/****************************************************************************
+ * OS Entry Point
+ ****************************************************************************/
+
+/* The following entry point must be linked to execute at 0x80000000 if it
+ * is to execute upon reset.
+ */
+	.text
+	.global 	__start
+	.type		__start, @function
+__start:
+
+	/* Set the IDLE thread stack pointer.  This stack will be used
+	 * through NuttX initialization and will, eventually, be inherited
+	 * by the IDLE thread when threading is enabled.
+	 */
+
+	lddpc		sp, .Lstackbase
+
+	/* Set up the vector base address so interrupts can be enabled. */
+
+	lda.w		r0, vectortab
+	mtsr		AVR32_EVBA, r0
+
+	/* Enable exception processing */
+
+	csrf		AVR32_SR_EM_SHIFT
+
+	/* Clear system BSS section */
+
+	lda.w		r0, _sbss		/* R =Start of .bss */
+	lda.w		r1, _ebss		/* r1=End of .bss */
+	mov			r2, 0			/* Value to write to .bss */
+	rjmp		2f				/* Start at the bottom of the loop */
+1:
+	st.d		r0++, r2		/* Zero .bss */
+2:
+	cp			r0, r1			/* Finished? */
+	brlo		1b				/* No... keep looping */
+
+	/* Copy system .data sections to new home in RAM. */
+
+#ifdef CONFIG_BOOT_RUNFROMFLASH
+
+	lda.w		r0, _sdata		/* r0=Start of .data section in RAM */
+	lda.w		r1, _edata		/* r1=End of .data section in RAM */
+	lda.w 		r2, _eronly		/* r2=Start of .data in FLASH */
+	rjmp		4f				/* Start at the bottom of the loop */
+3:
+	ld.d		r4, r2++		/* Fetch the next data value */
+	st.d		r0++, r4		/* Write it to the .data section */
+4:
+	cp			r0, r1			/* Finished? */
+	brlo		3b				/* No... keep looping */
+
+#endif
+
+	/* Clear the frame pointer and link register since this is the outermost
+	 * frame.
+	 */
+
+	mov			r7, 0
+	mov			lr, 0
+
+	/* Perform low-level initialization */
+
+	mcall		.Lavr_lowinit
+
+	/* Then jump to OS entry (will not return) */
+
+	lda.w		pc, nx_start
+
+.Lstackbase:
+	.word	_ebss+CONFIG_IDLETHREAD_STACKSIZE
+.Lavr_lowinit:
+	.word	avr_lowinit
+	.size	__start, .-__start
+
+	/* This global variable is unsigned long g_idle_topstack and is
+	 * exported from here only because of its coupling to other
+	 * uses of _ebss in this file
+	 */
+
+	.data
+	.align	4
+	.globl	g_idle_topstack
+	.type	g_idle_topstack, object
+g_idle_topstack:
+	.long	_ebss+CONFIG_IDLETHREAD_STACKSIZE
+	.size	g_idle_topstack, .-g_idle_topstack
+	.end
diff --git a/arch/avr/src/avr32/avr_releasepending.c b/arch/avr/src/avr32/avr_releasepending.c
new file mode 100644
index 0000000000..4f83151ef4
--- /dev/null
+++ b/arch/avr/src/avr32/avr_releasepending.c
@@ -0,0 +1,130 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_releasepending.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sched.h>
+#include <debug.h>
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "group/group.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_release_pending
+ *
+ * Description:
+ *   Release and ready-to-run tasks that have
+ *   collected in the pending task list.  This can call a
+ *   context switch if a new task is placed at the head of
+ *   the ready to run list.
+ *
+ ****************************************************************************/
+
+void up_release_pending(void)
+{
+  struct tcb_s *rtcb = this_task();
+
+  sinfo("From TCB=%p\n", rtcb);
+
+  /* Merge the g_pendingtasks list into the ready-to-run task list */
+
+  if (nxsched_merge_pending())
+    {
+      /* The currently active task has changed!  We will need to switch
+       * contexts.
+       *
+       * Update scheduler parameters.
+       */
+
+      nxsched_suspend_scheduler(rtcb);
+
+      /* Are we operating in interrupt context? */
+
+      if (g_current_regs)
+        {
+          /* Yes, then we have to do things differently.
+           * Just copy the g_current_regs into the OLD rtcb.
+           */
+
+           avr_savestate(rtcb->xcp.regs);
+
+          /* Restore the exception context of the rtcb at the (new) head
+           * of the ready-to-run task list.
+           */
+
+          rtcb = this_task();
+
+          /* Update scheduler parameters */
+
+          nxsched_resume_scheduler(rtcb);
+
+          /* Then switch contexts.  Any necessary address environment
+           * changes will be made when the interrupt returns.
+           */
+
+          avr_restorestate(rtcb->xcp.regs);
+        }
+
+      /* No, then we will need to perform the user context switch */
+
+      else
+        {
+          /* Switch context to the context of the task at the head of the
+           * ready to run list.
+           */
+
+          struct tcb_s *nexttcb = this_task();
+
+#ifdef CONFIG_ARCH_ADDRENV
+          /* Make sure that the address environment for the previously
+           * running task is closed down gracefully (data caches dump,
+           * MMU flushed) and set up the address environment for the new
+           * thread at the head of the ready-to-run list.
+           */
+
+          group_addrenv(nexttcb);
+#endif
+          /* Update scheduler parameters */
+
+          nxsched_resume_scheduler(nexttcb);
+
+          /* Then switch contexs */
+
+          avr_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
+
+          /* avr_switchcontext forces a context switch to the task at the
+           * head of the ready-to-run list.  It does not 'return' in the
+           * normal sense.  When it does return, it is because the blocked
+           * task is again ready to run and has execution priority.
+           */
+        }
+    }
+}
diff --git a/arch/avr/src/avr32/avr_schedulesigaction.c b/arch/avr/src/avr32/avr_schedulesigaction.c
new file mode 100644
index 0000000000..2828bd9058
--- /dev/null
+++ b/arch/avr/src/avr32/avr_schedulesigaction.c
@@ -0,0 +1,169 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_schedulesigaction.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <arch/avr32/avr32.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_schedule_sigaction
+ *
+ * Description:
+ *   This function is called by the OS when one or more
+ *   signal handling actions have been queued for execution.
+ *   The architecture specific code must configure things so
+ *   that the 'sigdeliver' callback is executed on the thread
+ *   specified by 'tcb' as soon as possible.
+ *
+ *   This function may be called from interrupt handling logic.
+ *
+ *   This operation should not cause the task to be unblocked
+ *   nor should it cause any immediate execution of sigdeliver.
+ *   Typically, a few cases need to be considered:
+ *
+ *   (1) This function may be called from an interrupt handler
+ *       During interrupt processing, all xcptcontext structures
+ *       should be valid for all tasks.  That structure should
+ *       be modified to invoke sigdeliver() either on return
+ *       from (this) interrupt or on some subsequent context
+ *       switch to the recipient task.
+ *   (2) If not in an interrupt handler and the tcb is NOT
+ *       the currently executing task, then again just modify
+ *       the saved xcptcontext structure for the recipient
+ *       task so it will invoke sigdeliver when that task is
+ *       later resumed.
+ *   (3) If not in an interrupt handler and the tcb IS the
+ *       currently executing task -- just call the signal
+ *       handler now.
+ *
+ * Assumptions:
+ *   Called from critical section
+ *
+ ****************************************************************************/
+
+void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
+{
+  sinfo("tcb=%p sigdeliver=%p\n", tcb, sigdeliver);
+
+  /* Refuse to handle nested signal actions */
+
+  if (!tcb->xcp.sigdeliver)
+    {
+      /* First, handle some special cases when the signal is
+       * being delivered to the currently executing task.
+       */
+
+      sinfo("rtcb=%p g_current_regs=%p\n",
+            this_task(), g_current_regs);
+
+      if (tcb == this_task())
+        {
+          /* CASE 1:  We are not in an interrupt handler and
+           * a task is signalling itself for some reason.
+           */
+
+          if (!g_current_regs)
+            {
+              /* In this case just deliver the signal now. */
+
+              sigdeliver(tcb);
+            }
+
+          /* CASE 2:  We are in an interrupt handler AND the
+           * interrupted task is the same as the one that
+           * must receive the signal, then we will have to modify
+           * the return state as well as the state in the TCB.
+           *
+           * Hmmm... there looks like a latent bug here: The following
+           * logic would fail in the strange case where we are in an
+           * interrupt handler, the thread is signalling itself, but
+           * a context switch to another task has occurred so that
+           * g_current_regs does not refer to the thread of this_task()!
+           */
+
+          else
+            {
+              /* Save registers that must be protected while the signal
+               * handler runs. These will be restored by the signal
+               * trampoline after the signal(s) have been delivered.
+               */
+
+              tcb->xcp.sigdeliver   = sigdeliver;
+              tcb->xcp.saved_pc     = g_current_regs[REG_PC];
+              tcb->xcp.saved_sr     = g_current_regs[REG_SR];
+
+              /* Then set up to vector to the trampoline with interrupts
+               * disabled
+               */
+
+              g_current_regs[REG_PC]  = (uint32_t)avr_sigdeliver;
+              g_current_regs[REG_SR] |= AVR32_SR_GM_MASK;
+
+              /* And make sure that the saved context in the TCB
+               * is the same as the interrupt return context.
+               */
+
+              avr_savestate(tcb->xcp.regs);
+            }
+        }
+
+      /* Otherwise, we are (1) signaling a task is not running
+       * from an interrupt handler or (2) we are not in an
+       * interrupt handler and the running task is signalling
+       * some non-running task.
+       */
+
+      else
+        {
+          /* Save registers that must be protected while the signal handler
+           * runs. These will be restored by the signal trampoline after
+           * the signals have been delivered.
+           */
+
+          tcb->xcp.sigdeliver       = sigdeliver;
+          tcb->xcp.saved_pc         = tcb->xcp.regs[REG_PC];
+          tcb->xcp.saved_sr         = tcb->xcp.regs[REG_SR];
+
+          /* Then set up to vector to the trampoline with interrupts
+           * disabled
+           */
+
+          tcb->xcp.regs[REG_PC]     = (uint32_t)avr_sigdeliver;
+          tcb->xcp.regs[REG_SR]    |= AVR32_SR_GM_MASK;
+        }
+    }
+}
diff --git a/arch/avr/src/avr32/avr_sigdeliver.c b/arch/avr/src/avr32/avr_sigdeliver.c
new file mode 100644
index 0000000000..ca81e807ce
--- /dev/null
+++ b/arch/avr/src/avr32/avr_sigdeliver.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_sigdeliver.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "sched/sched.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: avr_sigdeliver
+ *
+ * Description:
+ *   This is the a signal handling trampoline.  When a signal action was
+ *   posted.  The task context was mucked with and forced to branch to this
+ *   location with interrupts disabled.
+ *
+ ****************************************************************************/
+
+void avr_sigdeliver(void)
+{
+  struct tcb_s *rtcb = this_task();
+#if 0
+  uint32_t regs[XCPTCONTEXT_REGS + 3];  /* Why +3? See below */
+#else
+  uint32_t regs[XCPTCONTEXT_REGS];
+#endif
+
+  board_autoled_on(LED_SIGNAL);
+
+  sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
+        rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head);
+  DEBUGASSERT(rtcb->xcp.sigdeliver != NULL);
+
+  /* Save the return state on the stack. */
+
+  avr_copystate(regs, rtcb->xcp.regs);
+
+#ifndef CONFIG_SUPPRESS_INTERRUPTS
+  /* Then make sure that interrupts are enabled.  Signal handlers must always
+   * run with interrupts enabled.
+   */
+
+  up_irq_enable();
+#endif
+
+  /* Deliver the signal */
+
+  ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+
+  /* Output any debug messages BEFORE restoring errno (because they may
+   * alter errno), then disable interrupts again and restore the original
+   * errno that is needed by the user logic (it is probably EINTR).
+   */
+
+  sinfo("Resuming\n");
+  up_irq_save();
+
+  /* Modify the saved return state with the actual saved values in the
+   * TCB.  This depends on the fact that nested signal handling is
+   * not supported.  Therefore, these values will persist throughout the
+   * signal handling action.
+   *
+   * Keeping this data in the TCB resolves a security problem in protected
+   * and kernel mode:  The regs[] array is visible on the user stack and
+   * could be modified by a hostile program.
+   */
+
+  regs[REG_PC]         = rtcb->xcp.saved_pc;
+  regs[REG_SR]         = rtcb->xcp.saved_sr;
+  rtcb->xcp.sigdeliver = NULL;  /* Allows next handler to be scheduled */
+
+  /* Then restore the correct state for this thread of execution. This is an
+   * unusual case that must be handled by up_fullcontextresore. This case is
+   * unusual in two ways:
+   *
+   *   1. It is not a context switch between threads.  Rather,
+   *      avr_fullcontextrestore must behave more it more like a longjmp
+   *      within the same task, using the same stack.
+   *   2. In this case, avr_fullcontextrestore is called with r12 pointing to
+   *      a register save area on the stack to be destroyed.  This is
+   *      dangerous because there is the very real possibility that the new
+   *      stack pointer might overlap with the register save area and that
+   *      stack usage in avr_fullcontextrestore might corrupt the register
+   *      save data before the state is restored.  At present, there does
+   *      not appear to be any stack overlap problems.  If there were, then
+   *      adding 3 words to the size of register save structure size will
+   *      protect its contents.
+   */
+
+  board_autoled_off(LED_SIGNAL);
+  avr_fullcontextrestore(regs);
+}
diff --git a/arch/avr/src/avr32/avr_stackframe.c b/arch/avr/src/avr32/avr_stackframe.c
new file mode 100644
index 0000000000..37e4912259
--- /dev/null
+++ b/arch/avr/src/avr32/avr_stackframe.c
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_stackframe.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <arch/irq.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_stack_frame
+ *
+ * Description:
+ *   Allocate a stack frame in the TCB's stack to hold thread-specific data.
+ *   This function may be called anytime after up_create_stack() or
+ *   up_use_stack() have been called but before the task has been started.
+ *
+ *   Thread data may be kept in the stack (instead of in the TCB) if it is
+ *   accessed by the user code directly.  This includes such things as
+ *   argv[].  The stack memory is guaranteed to be in the same protection
+ *   domain as the thread.
+ *
+ *   The following TCB fields will be re-initialized:
+ *
+ *   - adj_stack_size: Stack size after removal of the stack frame from
+ *     the stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb:  The TCB of new task
+ *   - frame_size:  The size of the stack frame to allocate.
+ *
+ *  Returned Value:
+ *   - A pointer to bottom of the allocated stack frame.  NULL will be
+ *     returned on any failures.  The alignment of the returned value is
+ *     the same as the alignment of the stack itself.
+ *
+ ****************************************************************************/
+
+FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
+{
+  FAR void *ret;
+
+  /* Align the frame_size */
+
+  frame_size = STACK_ALIGN_UP(frame_size);
+
+  /* Is there already a stack allocated? Is it big enough? */
+
+  if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
+    {
+      return NULL;
+    }
+
+  ret = tcb->stack_base_ptr;
+  memset(ret, 0, frame_size);
+
+  /* Save the adjusted stack values in the struct tcb_s */
+
+  tcb->stack_base_ptr  = (FAR uint8_t *)tcb->stack_base_ptr + frame_size;
+  tcb->adj_stack_size -= frame_size;
+
+  /* And return the pointer to the allocated region */
+
+  return ret;
+}
diff --git a/arch/avr/src/avr32/avr_switchcontext.S b/arch/avr/src/avr32/avr_switchcontext.S
new file mode 100644
index 0000000000..4eb815c88a
--- /dev/null
+++ b/arch/avr/src/avr32/avr_switchcontext.S
@@ -0,0 +1,107 @@
+/************************************************************************************
+ * arch/avr/src/avr32/avr_switchcontext.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ************************************************************************************/
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <arch/irq.h>
+#include <arch/avr32/avr32.h>
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Symbols
+ ************************************************************************************/
+
+	.file		"avr_switchcontext.S"
+
+/************************************************************************************
+ * Macros
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: avr_switchcontext
+ *
+ * Description:
+ *   Save the current thread context and restore the specified context.  The full
+ *   C function prototype is:
+ *
+ *   void avr_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
+ *
+ * Returned Value:
+ *   avr_switchcontext forces a context switch to the task "canned" in restoreregs.
+ *   It does not 'return' in the normal sense, rather, it will context switch back
+ *   to the function point.  When it does 'return,' it is because the blocked
+ *   task hat was "pickeled" in the saveregs "can" is again ready to run and has
+ *   execution priority.
+ *
+ * Assumptions:
+ *   global interrupts disabled by the caller.
+ *
+ ************************************************************************************/
+
+	.text
+	.globl		avr_switchcontext
+	.type		avr_switchcontext, @function
+avr_switchcontext:
+	/* "Pickle" the current thread context in the saveregs "can."  r12=saveregs.    */
+	/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx                       */
+	/*     ^r12                                                                     */
+	/* Sample SR and set r12 to just after the LR storage location.                 */
+	/*     xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx                       */
+	/*                                         ^r12                                 */
+
+	mfsr	r10, AVR32_SR
+	sub		r12, -4*(REG_LR+1)
+
+	/* Then "push" PC=LR, LR, SR, and SP as they are on entry.                      */
+	/*     xx xx xx xx xx xx xx xx SP SR PC LR xx xx xx xx xx                       */
+	/*                             ^r12                                             */
+
+	st.w	--r12, lr
+	st.w	--r12, lr
+	st.w	--r12, r10
+	st.w	--r12, sp
+
+	/* Save the preserved/static registers, r0-r7.  There is no reason to save the  */
+	/* scratch/volatile registers, r8-r12, in this context.                         */
+	/*     07 06 05 04 03 02 01 00 SP SR PC LR xx xx xx xx xx                       */
+	/*     ^r12                                                                     */
+
+	stm		--r12, r0-r7
+
+	/* Finally, let avr_fullcontextrestore handling the re-instatement of the thread */
+	/* "canned" in restoregs.                                                       */
+
+	mov		r12, r11
+	lddpc	pc, .Lavr_fullcontextrestore
+
+.Lavr_fullcontextrestore:
+	.word	avr_fullcontextrestore
+	.size	avr_switchcontext, .-avr_switchcontext
+	.end
diff --git a/arch/avr/src/avr32/avr_syscall6.S b/arch/avr/src/avr32/avr_syscall6.S
new file mode 100644
index 0000000000..4e21170399
--- /dev/null
+++ b/arch/avr/src/avr32/avr_syscall6.S
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_syscall6.S
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/*   Based on Bran's kernel development tutorials. Rewritten for JamesM's
+ *   kernel development tutorials.
+ */
+
+	.file	"up_syscall6.S"
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Symbols
+ ****************************************************************************/
+
+/****************************************************************************
+ * .text
+ ****************************************************************************/
+
+	.text
+
+/****************************************************************************
+ * Name: sys_call6
+ *
+ * C Prototype:
+ *   uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
+ *                       uintptr_t parm2, uintptr_t parm3,
+ *                       uintptr_t parm4, uintptr_t parm5,
+ *                       uintptr_t parm6);
+ *
+ ****************************************************************************/
+
+	.global	sys_call6
+	.type	sys_call6, @function
+	.align	2
+
+sys_call6:
+	stm		--sp, r3, r5, r6, lr
+	sub		lr, sp, -16
+	mov		r8, r12
+	ldm		lr, r3, r5, r9-r12
+	scall
+	ldm		sp++, r3, r5, r6, pc
+
+	.size	sys_call6, . - sys_call6
diff --git a/arch/avr/src/avr32/avr_unblocktask.c b/arch/avr/src/avr32/avr_unblocktask.c
new file mode 100644
index 0000000000..ed99d3dd5c
--- /dev/null
+++ b/arch/avr/src/avr32/avr_unblocktask.c
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_unblocktask.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
+#include "sched/sched.h"
+#include "group/group.h"
+#include "clock/clock.h"
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_unblock_task
+ *
+ * Description:
+ *   A task is currently in the ready-to-run list but has been prepped
+ *   to execute. Restore its context, and start execution.
+ *
+ * Input Parameters:
+ *   tcb: Refers to the head task of the ready-to-run list
+ *     which will be executed.
+ *   rtcb: Refers to the running task which will be blocked.
+ *
+ ****************************************************************************/
+
+void up_unblock_task(struct tcb_s *tcb, struct tcb_s *rtcb)
+{
+  /* Update scheduler parameters */
+
+  nxsched_suspend_scheduler(rtcb);
+
+  /* Are we in an interrupt handler? */
+
+  if (g_current_regs)
+    {
+      /* Yes, then we have to do things differently.
+       * Just copy the g_current_regs into the OLD rtcb.
+       */
+
+      avr_savestate(rtcb->xcp.regs);
+
+      /* Update scheduler parameters */
+
+      nxsched_resume_scheduler(tcb);
+
+      /* Then switch contexts.  Any new address environment needed by
+       * the new thread will be instantiated before the return from
+       * interrupt.
+       */
+
+      avr_restorestate(tcb->xcp.regs);
+    }
+
+  /* No, then we will need to perform the user context switch */
+
+  else
+    {
+#ifdef CONFIG_ARCH_ADDRENV
+      /* Make sure that the address environment for the previously
+       * running task is closed down gracefully (data caches dump,
+       * MMU flushed) and set up the address environment for the new
+       * thread at the head of the ready-to-run list.
+       */
+
+      group_addrenv(tcb);
+#endif
+      /* Update scheduler parameters */
+
+      nxsched_resume_scheduler(tcb);
+
+      /* Then switch contexts */
+
+      avr_switchcontext(rtcb->xcp.regs, tcb->xcp.regs);
+
+      /* avr_switchcontext forces a context switch to the task at the
+       * head of the ready-to-run list.  It does not 'return' in the
+       * normal sense.  When it does return, it is because the blocked
+       * task is again ready to run and has execution priority.
+       */
+    }
+}
diff --git a/arch/avr/src/avr32/avr_usestack.c b/arch/avr/src/avr32/avr_usestack.c
new file mode 100644
index 0000000000..280596c87b
--- /dev/null
+++ b/arch/avr/src/avr32/avr_usestack.c
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * arch/avr/src/avr32/avr_usestack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <sched.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+
+#include "avr_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ *   Setup up stack-related information in the TCB using pre-allocated stack
+ *   memory.  This function is called only from nxtask_init() when a task or
+ *   kernel thread is started (never for pthreads).
+ *
+ *   The following TCB fields must be initialized:
+ *
+ *   - adj_stack_size: Stack size after adjustment for hardware,
+ *     processor, etc.  This value is retained only for debug
+ *     purposes.
+ *   - stack_alloc_ptr: Pointer to allocated stack
+ *   - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
+ *     Arguments has been removed from the stack allocation.
+ *
+ * Input Parameters:
+ *   - tcb: The TCB of new task
+ *   - stack_size:  The allocated stack size.
+ *
+ *   NOTE:  Unlike up_stack_create() and up_stack_release, this function
+ *   does not require the task type (ttype) parameter.  The TCB flags will
+ *   always be set to provide the task type to up_use_stack() if it needs
+ *   that information.
+ *
+ ****************************************************************************/
+
+int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
+{
+  uintptr_t top_of_stack;
+  size_t size_of_stack;
+
+#ifdef CONFIG_TLS_ALIGNED
+  /* Make certain that the user provided stack is properly aligned */
+
+  DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
+#endif
+
+  /* Is there already a stack allocated? */
+
+  if (tcb->stack_alloc_ptr)
+    {
+      /* Yes.. Release the old stack allocation */
+
+      up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
+    }
+
+  /* Save the new stack allocation */
+
+  tcb->stack_alloc_ptr = stack;
+
+  /* If stack debug is enabled, then fill the stack with a recognizable value
+   * that we can use later to test for high water marks.
+   */
+
+#ifdef CONFIG_STACK_COLORATION
+  memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size);
+#endif
+
+  /* The AVR32 uses a push-down stack:  the stack grows
+   * toward loweraddresses in memory.  The stack pointer
+   * register, points to the lowest, valid work address
+   * (the "top" of the stack).  Items on the stack are
+   * referenced as positive word offsets from sp.
+   */
+
+  top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
+
+  /* The AVR32 stack must be aligned at word (4 byte)
+   * boundaries. If necessary top_of_stack must be rounded
+   * down to the next boundary
+   */
+
+  top_of_stack &= ~3;
+  size_of_stack = top_of_stack - (uintptr_t)tcb->stack_alloc_ptr;
+
+  /* Save the adjusted stack values in the struct tcb_s */
+
+  tcb->stack_base_ptr = tcb->stack_alloc_ptr;
+  tcb->adj_stack_size = size_of_stack;
+
+  return OK;
+}
diff --git a/arch/avr/src/avr32/up_blocktask.c b/arch/avr/src/avr32/up_blocktask.c
deleted file mode 100644
index 5da62c9562..0000000000
--- a/arch/avr/src/avr32/up_blocktask.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr32/up_blocktask.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdbool.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/sched.h>
-
-#include "sched/sched.h"
-#include "group/group.h"
-#include "up_internal.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_block_task
- *
- * Description:
- *   The currently executing task has already removed from ready-to-run list.
- *   Save its context and switch to the next running task at the head of the
- *   ready-to-run list.
- *
- * Input Parameters:
- *   rtcb: Reference to the running task which is different to the
- *     task (next running task) at the head of the list.
- *
- ****************************************************************************/
-
-void up_block_task(struct tcb_s *rtcb)
-{
-  /* Update scheduler parameters */
-
-  nxsched_suspend_scheduler(rtcb);
-
-  /* Are we in an interrupt handler? */
-
-  if (g_current_regs)
-    {
-      /* Yes, then we have to do things differently.
-       * Just copy the g_current_regs into the OLD rtcb.
-       */
-
-      up_savestate(rtcb->xcp.regs);
-
-      /* Restore the exception context of the rtcb at the (new) head
-       * of the ready-to-run task list.
-       */
-
-      rtcb = this_task();
-
-      /* Reset scheduler parameters */
-
-      nxsched_resume_scheduler(rtcb);
-
-      /* Then switch contexts.  Any new address environment needed by
-       * the new thread will be instantiated before the return from
-       * interrupt.
-       */
-
-      up_restorestate(rtcb->xcp.regs);
-    }
-
-  /* No, then we will need to perform the user context switch */
-
-  else
-    {
-      /* Get the context of the task at the head of the ready to
-       * run list.
-       */
-
-      struct tcb_s *nexttcb = this_task();
-
-#ifdef CONFIG_ARCH_ADDRENV
-      /* Make sure that the address environment for the previously
-       * running task is closed down gracefully (data caches dump,
-       * MMU flushed) and set up the address environment for the new
-       * thread at the head of the ready-to-run list.
-       */
-
-      group_addrenv(nexttcb);
-#endif
-      /* Reset scheduler parameters */
-
-      nxsched_resume_scheduler(nexttcb);
-
-      /* Then switch contexts */
-
-      up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
-
-      /* up_switchcontext forces a context switch to the task at the
-       * head of the ready-to-run list.  It does not 'return' in the
-       * normal sense.  When it does return, it is because the blocked
-       * task is again ready to run and has execution priority.
-       */
-    }
-}
diff --git a/arch/avr/src/avr32/up_copystate.c b/arch/avr/src/avr32/up_copystate.c
deleted file mode 100644
index b893549a35..0000000000
--- a/arch/avr/src/avr32/up_copystate.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr32/up_copystate.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <stdint.h>
-
-#include <arch/avr32/irq.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_copystate
- ****************************************************************************/
-
-/* A little faster than most memcpy's */
-
-void up_copystate(uint32_t *dest, uint32_t *src)
-{
-  int i;
-
-  /* The state is copied from the stack to the TCB, but only a reference is
-   * passed to get the state from the TCB.  So the following check avoids
-   * copying the TCB save area onto itself:
-   */
-
-  if (src != dest)
-    {
-      for (i = 0; i < XCPTCONTEXT_REGS; i++)
-        {
-          *dest++ = *src++;
-        }
-    }
-}
diff --git a/arch/avr/src/avr32/up_createstack.c b/arch/avr/src/avr32/up_createstack.c
deleted file mode 100644
index 3b7a7435f6..0000000000
--- a/arch/avr/src/avr32/up_createstack.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/****************************************************************************
- * arch/avr/src/avr32/up_createstack.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/compiler.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <sched.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/arch.h>
-#include <nuttx/tls.h>
-#include <nuttx/board.h>
-#include <arch/board/board.h>
-
-#include "up_internal.h"
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_create_stack
- *
- * Description:
- *   Allocate a stack for a new thread and setup up stack-related information
- *   in the TCB.
- *
- *   The following TCB fields must be initialized by this function:
- *
- *   - adj_stack_size: Stack size after adjustment for hardware, processor,
- *     etc.  This value is retained only for debug purposes.
- *   - stack_alloc_ptr: Pointer to allocated stack
... 105571 lines suppressed ...