Browse Source

[AVR] Add device information in .note.gnu.avr.deviceinfo section.

ccrause 1 month ago
parent
commit
0d4474e11c
7 changed files with 90 additions and 8 deletions
  1. 3 1
      compiler/aasmbase.pas
  2. 1 1
      compiler/aasmcnst.pas
  3. 13 3
      compiler/aggas.pas
  4. 67 0
      compiler/avr/navrutil.pas
  5. 2 1
      compiler/ogbase.pas
  6. 2 1
      compiler/ogelf.pas
  7. 2 1
      compiler/ogwasm.pas

+ 3 - 1
compiler/aasmbase.pas

@@ -181,7 +181,9 @@ interface
          sec_heap,
          { dwarf based/gcc style exception handling }
          sec_gcc_except_table,
-         sec_arm_attribute
+         sec_arm_attribute,
+         { Used for GNU .note sections }
+         sec_note
        );
 
        TObjCAsmSectionType = sec_objc_class..sec_objc_protolist;

+ 1 - 1
compiler/aasmcnst.pas

@@ -1021,7 +1021,7 @@ implementation
               if not(section in [low(TObjCAsmSectionType)..high(TObjCAsmSectionType)]) then
                 prelist.concat(tai_directive.Create(asd_reference,asmsym.name))
              end
-           else if section<>sec_fpc then
+           else if not(section in [sec_fpc,sec_note]) then
              internalerror(2015101402);
          end;
 

+ 13 - 3
compiler/aggas.pas

@@ -206,6 +206,7 @@ implementation
            create_smartlink_sections and
            (atype<>sec_toc) and
            (atype<>sec_user) and
+           (atype<>sec_note) and
            { on embedded systems every byte counts, so smartlink bss too }
            ((atype<>sec_bss) or (target_info.system in (systems_embedded+systems_freertos)));
       end;
@@ -282,7 +283,8 @@ implementation
           '.stack',
           '.heap',
           '.gcc_except_table',
-          '.ARM.attributes'
+          '.ARM.attributes',
+          '.note'
         );
         secnames_pic : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
           '.text',
@@ -343,7 +345,8 @@ implementation
           '.stack',
           '.heap',
           '.gcc_except_table',
-          '..ARM.attributes'
+          '..ARM.attributes',
+          '.note'
         );
       var
         sep     : string[3];
@@ -398,6 +401,9 @@ implementation
         if atype=sec_user then
           secname:=aname;
 
+        if atype=sec_note then
+          secname:='.note'+aname;
+
         if is_smart_section(atype) and (aname<>'') then
           begin
             case aorder of
@@ -580,6 +586,7 @@ implementation
              if not(atype in [sec_data,sec_rodata,sec_rodata_norel]) and
                 not(asminfo^.id=as_solaris_as) and
                 not(atype=sec_fpc) and
+                not(atype=sec_note) and
                 not(target_info.system in (systems_embedded+systems_freertos)) then
                begin
                  usesectionflags:=true;
@@ -646,6 +653,8 @@ implementation
                     internalerror(2006031101);
                 end;
               end;
+            sec_note :
+              writer.AsmWrite(', "", @note');
           else
             { GNU AS won't recognize '.text.n_something' section name as belonging
               to '.text' and assigns default attributes to it, which is not
@@ -2264,7 +2273,8 @@ implementation
          sec_none (* sec_stack *),
          sec_none (* sec_heap *),
          sec_none (* gcc_except_table *),
-         sec_none (* sec_arm_attribute *)
+         sec_none (* sec_arm_attribute *),
+         sec_none (* sec_note *)
         );
       begin
         Result := inherited SectionName (SecXTable [AType], AName, AOrder);

+ 67 - 0
compiler/avr/navrutil.pas

@@ -34,9 +34,14 @@ interface
 
 
   type
+
+    { tavrnodeutils }
+
     tavrnodeutils = class(tnodeutils)
     protected
       class procedure insert_init_final_table(main: tmodule; entries:tfplist); override;
+    public
+      class procedure InsertMemorySizes; override;
     end;
 
 implementation
@@ -108,6 +113,68 @@ implementation
       inherited insert_init_final_table(main,entries);
     end;
 
+  class procedure tavrnodeutils.InsertMemorySizes;
+    var
+      tcb: ttai_typedconstbuilder;
+      notename, strtable: shortstring;
+      sym: tasmsymbol;
+      defstr, defu32: tdef;
+    begin
+      { Store device information in the .note.gnu.avr.deviceinfo section.
+
+        Layout of.note.gnu.avr.deviceinfo:
+         note_name_len: dword
+         note_desc_len: dword // Size of the Tavr_desc data record
+         note_type: dword = 1
+         Tavr_desc = record
+           note_name: char[note_name_len] = 'AVR'#0;
+           flash_start,
+           flash_size,
+           sram_start,
+           sram_size,
+           eeprom_start,
+           eeprom_size: dword;
+           offset_table_len: dword;
+           offset_table: char[] = #0+mcuname#0+#0;
+         end }
+
+      notename:='AVR'#0;
+      strtable:=#0+lower(embedded_controllers[current_settings.controllertype].controllertypestr)+#0#0;
+      tcb:=ctai_typedconstbuilder.create([tcalo_no_dead_strip]);
+      defu32:=corddef.create(u32bit,0,$FFFFFFFF,false);
+      tcb.maybe_begin_aggregate(defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(length(notename)),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(length(strtable)+32),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(1),defu32);
+      defstr:=carraydef.getreusable(cansichartype,length(notename));
+      tcb.maybe_begin_aggregate(defstr);
+      tcb.emit_tai(Tai_string.Create(notename),defstr);
+      tcb.maybe_begin_aggregate(defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].flashbase),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].flashsize),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].srambase),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].sramsize),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].eeprombase),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(embedded_controllers[current_settings.controllertype].eepromsize),defu32);
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(8),defu32);  // Size of string offset table
+      tcb.emit_tai(tai_const.Create_32bit_unaligned(1),defu32);  // Offset of string in table
+      tcb.maybe_begin_aggregate(defstr);
+      tcb.emit_tai(Tai_string.Create(strtable),defstr);
+      tcb.maybe_end_aggregate(defstr);
+      tcb.maybe_end_aggregate(defu32);
+      tcb.maybe_end_aggregate(defstr);
+      tcb.maybe_end_aggregate(defu32);
+
+      sym:=current_asmdata.DefineAsmSymbol('__AVR_deviceinfo',AB_LOCAL,AT_DATA,defstr);
+      current_asmdata.asmlists[al_globals].concatlist(
+        tcb.get_final_asmlist(sym,defstr,sec_note,'.gnu.avr.deviceinfo',const_align(32))
+      );
+      defu32.free;
+      tcb.free;
+
+      inherited InsertMemorySizes;
+    end;
+
 begin
   cnodeutils:=tavrnodeutils;
 end.

+ 2 - 1
compiler/ogbase.pas

@@ -1528,7 +1528,8 @@ implementation
           {stack} [oso_load,oso_write],
           {heap} [oso_load,oso_write],
           {gcc_except_table} [oso_data,oso_load],
-          {arm_attribute} [oso_data]
+          {arm_attribute} [oso_data],
+          {note} [oso_Data,oso_note]
         );
       begin
         if target_asm.id in asms_int_coff then

+ 2 - 1
compiler/ogelf.pas

@@ -568,7 +568,8 @@ implementation
           '.stack',
           '.heap',
           '.gcc_except_table',
-          '.ARM.attributes'
+          '.ARM.attributes',
+          '.note'
         );
       var
         sep : string[3];

+ 2 - 1
compiler/ogwasm.pas

@@ -1015,7 +1015,8 @@ implementation
           '.stack',
           '.heap',
           '.gcc_except_table',
-          '.ARM.attributes'
+          '.ARM.attributes',
+          '.note'
         );
       var
         sep     : string[3];