5.1.6.5 Section Directive Examples - Boot/Secure Segments

Program Memory

Attributes can be used to declare protected functions in secure segments:

  .section *,code,boot
  .global func1
func1:
  return

  .section *,code,secure
  .global func2
func2:
  return

A secure function is defined by the combination of .section and .global directives, and a label. It is recommended that each secure function be defined in a separate section. If the function will be assigned an access entry point, separate sections are required.

An optional argument to boot or secure can be used to specify a protected access entry point:

  .section *,code,boot(3)
  .global func3
func3:
  return

  .section *,code,secure(4)
  .global func4
func4:
  return

The optional argument is valid only in code sections. Integers that represent access entry slots must be in the range 0..15 or 17..31. In addition to an entry slot number, the value unused may be used to specify an entry for all unused slots in the access entry area:

  .section *,code,boot(unused)
  .global func_default
func_default:
  return

An interrupt service routine may be specified with the value isr:

  .section *,code,boot(isr)
  .global func_isr
func_default:
  retfie

A section identified with boot(isr) or secure(isr) will be assigned to access entry slot 16, which is reserved for interrupt functions.

Data Memory

The boot and secure attributes can be used to define protected variables in boot RAM or secure RAM:

  .section *,bss,boot
  .global boot_dat
boot_dat:
  .space 32

  .section *,bss,secure
  .global secure_dat
secure_dat:
  .space 32

There is no support for initialized data in protected RAM segments. Therefore boot or secure cannot be used in combination with attribute data. A diagnostic will be reported if initial values are specified in a section that has been designated boot or secure.

Constants in Non-Volatile Memory

Constants in non-volatile memory can be protected by using the boot or secure attribute in combination with psv or eedata:

  .section *,psv,boot
  .global key1
key1:
  .ascii “abcdefg”
  .section *,eedata,boot
  .global key2
key2:
  .ascii “hijklm”