1

Comme on n'est jamais mieux servi que par soi même, voici le patch set pour le support des sections BSS dans les Flash OS:
Quelques infos:
J'ai essayé d'être le plus propre et le moins intrusif que possible.
Ca doit marcher pour générer un OS avec une section BSS en RAM.

Trus à faire:
Ajouter plus de symboles spéciaux (fin du bss, debut des archives, ...)
Trouver un moyen d'optimiser la passe BSS: toutes les références BSS sont sur 4 octets même si 2 devrait suffire (car addresse < 32K). Je ne sais pas comment faire dans ld-tigcc facilement.

diff -ur ld-tigcc/export/exp_os.c ld-tigcc.maversion/export/exp_os.c
--- ld-tigcc/export/exp_os.c	2004-12-23 00:12:09.000000000 +0100
+++ ld-tigcc.maversion/export/exp_os.c	2008-02-26 20:56:41.000000000 +0100
@@ -110,33 +110,42 @@
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);
+                        OFFSET TargetLocation = 0;
 			
 			// If this can be resolved to a calculator-dependent value, write the
 			// value into the section data.
 			if (EmitCalcBuiltinValue (Reloc, DestCalc, File, FileSize, DataStart))
 				continue;
 			
-			// We can only emit relocs with a target symbol in the same section.
-			if (!(Reloc->Target.Symbol))
-				FailWithError (CurFileName, "Unresolved reference to `%s'.", Reloc->Target.SymbolName);
-			if (Reloc->Target.Symbol->Parent != MainSection)
-				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);
-			
 			// We can only emit 4-byte absolute relocs.
 			if (Reloc->Relative || (Reloc->Size != 4))
 				FailWithError (CurFileName, "Cannot emit %ld byte %s reloc to `%s'.", (long) Reloc->Size, Reloc->Relative ? "relative" : "absolute", Reloc->Target.SymbolName);
-			
-			{
-				OFFSET TargetLocation = GetLocationOffset (MainSection, &(Reloc->Target)) + Reloc->FixedOffset;
+
+			if (!(Reloc->Target.Symbol))
+				FailWithError (CurFileName, "Unresolved reference to `%s'.", Reloc->Target.SymbolName);
+
+                        // Check for BSS Section
+                        if (Program->OptimizeInfo->FlashOSBSSStart > 0
+                            && Reloc->Target.Symbol->Parent == Program->BSSSection) {
+                          TargetLocation = GetLocationOffset (Program->BSSSection, &(Reloc->Target)) + Reloc->FixedOffset;
+                          TargetLocation += (OFFSET) (Program->OptimizeInfo->FlashOSBSSStart);
+                          ExportSeek (File, DataStart + Reloc->Location);
+                          ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
+                          continue;
+                        }
+			// We can only emit relocs with a target symbol in the same section.
+			else if (Reloc->Target.Symbol->Parent != MainSection)
+				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);
+
+			TargetLocation = GetLocationOffset (MainSection, &(Reloc->Target)) + Reloc->FixedOffset;
 				
-				TargetLocation += (OFFSET) (ROMBase + 0x12000);
-				ExportSeek (File, DataStart + Reloc->Location);
-				ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
+                        TargetLocation += (OFFSET) (ROMBase + 0x12000);
+                        ExportSeek (File, DataStart + Reloc->Location);
+                        ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
 				
-				// Do not increase the statistics, since that would give a false
-				// impression that the relocation entries actually take up some
-				// space in the OS.
-			}
+                        // Do not increase the statistics, since that would give a false
+                        // impression that the relocation entries actually take up some
+                        // space in the OS.
 		}
 	}
 	
diff -ur ld-tigcc/intrface.h ld-tigcc.maversion/intrface.h
--- ld-tigcc/intrface.h	2005-03-31 06:12:52.000000000 +0200
+++ ld-tigcc.maversion/intrface.h	2008-02-26 20:42:06.000000000 +0100
@@ -52,6 +52,8 @@
 		CutRanges,          // Cut unneeded section ranges when optimizing.
 		ReorderSections,    // Reorder sections to shorten references.
 		MergeConstants;     // Merge constants and strings to avoid duplication.
+        B4
+                FlashOSBSSStart;    // Flash OS Start of BSS Section
 	SI4
 		ProgramSize,            // Size of the on-calc program variable.
 		DataSize,               // Size of the data variable.
diff -ur ld-tigcc/main.c ld-tigcc.maversion/main.c
--- ld-tigcc/main.c	2005-04-22 21:34:10.000000000 +0200
+++ ld-tigcc.maversion/main.c	2008-02-26 20:42:02.000000000 +0100
@@ -389,6 +389,8 @@
 #ifdef FLASH_OS_SUPPORT
 				if (Program.Type == PT_FLASH_OS)
 				{
+                                        if (OptInfo->FlashOSBSSStart > 0 && Program.BSSSection)
+                                          Program.BSSSection->Handled = TRUE;
 					// Flash OS export: merge startup and normal sections separately.
 					// The resulting two parts are merged later, padding the first
 					// part to the full 24 KB of the OS startup area (base 1)
diff -ur ld-tigcc/main_opt.inc ld-tigcc.maversion/main_opt.inc
--- ld-tigcc/main_opt.inc	2006-07-16 03:58:15.000000000 +0200
+++ ld-tigcc.maversion/main_opt.inc	2008-02-26 20:42:17.000000000 +0100
@@ -67,6 +67,7 @@
 					        "     --native             Link in TIGCC native mode\n"
 #ifdef FLASH_OS_SUPPORT
 					        "     --flash-os           Create (unsigned) Flash OS\n"
+						"     --flash-os-bss-start=<start> Start of the BSS Section in RAM (For Flash OS)\n"
 #endif /* FLASH_OS_SUPPORT */
 #ifdef FARGO_SUPPORT
 					        "     --fargo              Create Fargo II program\n"
@@ -131,6 +132,16 @@
 				{
 					Program.Type = PT_FLASH_OS;
 					Warning (NULL, "Flash OS support in TIGCC is experimental.");
+					OutputBin = TRUE;
+				}
+				else
+				if (!(strncmp (Arg, "flash-os-bss-start=", sizeof ("flash-os-bss-start=") - 1)))
+				{
+					char *End;
+					Arg += sizeof ("flash-os-bss-start=") - 1;
+					OptInfo->FlashOSBSSStart = strtoul (Arg, &End, 0);
+					if (End == Arg)
+					   Error (NULL, "Invalid number for flash-os-bss-start");
 				}
 				else
 #endif /* FLASH_OS_SUPPORT */
diff -ur ld-tigcc/manip.c ld-tigcc.maversion/manip.c
--- ld-tigcc/manip.c	2005-07-02 00:08:58.000000000 +0200
+++ ld-tigcc.maversion/manip.c	2008-02-26 20:28:56.000000000 +0100
@@ -955,7 +955,7 @@
 {
 	BOOLEAN MergeForward = FALSE;
 	SECTION *CurMergedSection = NULL, *Section, *NextSection;
-	
+
 	// For each section...
 	for (Section = GetLast (Program->Sections); Section; Section = NextSection)
 	{
diff -ur ld-tigcc/special.c ld-tigcc.maversion/special.c
--- ld-tigcc/special.c	2005-08-03 02:31:49.000000000 +0200
+++ ld-tigcc.maversion/special.c	2008-02-26 20:30:42.000000000 +0100
@@ -332,8 +332,11 @@
 		Result = Result && AddGlobalImport (Program, "__handle_constructors");
 	if (Program->Destructors.Start)
 		Result = Result && AddGlobalImport (Program, "__handle_destructors");
-	if (Program->BSSSection && Program->BSSSection->Initialized)
-		Result = Result && AddGlobalImport (Program, "__initialize_bss");
+	if (Program->BSSSection && Program->BSSSection->Initialized
+#ifdef FLASH_OS_SUPPORT
+            && Program->Type != PT_FLASH_OS
+#endif /* FLASH_OS_SUPPORT */
+          )	Result = Result && AddGlobalImport (Program, "__initialize_bss");
 	
 	// Handle BSS section if any.
 	if (Program->BSSSection && (!(Program->BSSSection->Handled)))

2

Pour le problème de passer de 4 octets à 2 par symbole BSS, je pense qu'il faudrait remonter la passe qui résoud les symboles BSS beaucoup plus tôt.
Des idées ?

!call Kevin Kofler
--- Call : Kevin Kofler appelé(e) sur ce topic ...

3

Tiens, c'est aussi simple que ça? Merci pour le patch. Quelques commentaires:
* Vu que tu as changé l'interface entre TIGCC IDE et link.dll (intrface.h), il faudra incrémenter le numéro de version de l'interface. (Mais bon, c'est trivial pour moi de changer ça.)
* Il faudra aussi que je rajoute cette option aux IDEs et à la documentation.
* Pour passer le relogement de 32 bits à 16 bits, AMHA, la meilleure solution est de rajouter une transformation qui fait ça aux fameuses optimisations linker (bincode/fix_m68k.c) (pour passer le relogement ABS32 en un relogement ABS16). Problème: comment savoir quelle sera l'adresse effective du symbole BSS? (Ou alors on part du principe que le BSS s'arrête à 0x7FFF? Mais ce n'est pas le cas dans AMS, du moins pour les AMS récents qui débordent jusqu'à 0x9xxx.) Je signale aussi que cette optimisation ne peut fonctionner convenablement qu'avec le range-cutting, donc tu as intérêt à rendre PedroM compilable avec cette option (soit tu vires les (lbl1-lbl2)/4 et co. de PedroM, soit tu implémentes ça dans assembleur et linker).
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

4

5

Kevin Kofler (./3) :
Tiens, c'est aussi simple que ça?

Il semblerait. Mais il faudrait tester plus en profondeur que ce que j'ai fait.
Et que j'inclue les nouveaux symboles (donc si tu pouvais attendre pour faire le merge de ton coté...)
Kevin Kofler (./3) :
* Vu que tu as changé l'interface entre TIGCC IDE et link.dll (intrface.h), il faudra incrémenter le numéro de version de l'interface. (Mais bon, c'est trivial pour moi de changer ça.)

Ok
Kevin Kofler (./3) :
* Pour passer le relogement de 32 bits à 16 bits, AMHA, la meilleure solution est de rajouter une transformation qui fait ça aux fameuses optimisations linker (bincode/fix_m68k.c) (pour passer le relogement ABS32 en un relogement ABS16). Problème: comment savoir quelle sera l'adresse effective du symbole BSS? (Ou alors on part du principe que le BSS s'arrête à 0x7FFF? Mais ce n'est pas le cas dans AMS, du moins pour les AMS récents qui débordent jusqu'à 0x9xxx.) Je signale aussi que cette optimisation ne peut fonctionner convenablement qu'avec le range-cutting, donc tu as intérêt à rendre PedroM compilable avec cette option (soit tu vires les (lbl1-lbl2)/4 et co. de PedroM, soit tu implémentes ça dans assembleur et linker).

C'est pas simple.
Je suppose qu'il n'y a pas d'infrastructure pour simplifier le passage ABS32 -> ABS16. Tout est à faire ? Parce que sans çà, je ne commence pas à le faire.
Pour le BSS qui s'arrête à 0x7FFF, soit on rajoute une nouvelle option, soit on le sait car on a déjà fusionné les section .bss

Pour PedroM, on doit pouvoir s'en sortir en jonglant avec les section (et désactiver le range cutting pour les sections définissant des tables). Mais je ne sais pas si c'est possible à l'heure actuelle (ie par section, ou par fichier ?).

6

Martial Demolins (./4) :
(bon je dirais que tout ça, ça sent bon la bêta 0.82 dans les 15 jours à venir embarrassed)

Arrête de rêver. tongue

7


# __ld_bss_start
# __ld_bss_end
# __ld_bss_size

Ces trois symboles sont parfaitement résolues aux bonnes adresses avec le patch.
Reste à voir si on la garantie que __ld_bss_size ne puisse pas être impair. Je crois que oui. Kevin ?

8

Ajout du support de __ld_archive_start :
--- ld-tigcc.orig/special.c     2005-08-03 02:31:49.000000000 +0200
+++ ld-tigcc/special.c  2008-02-26 23:06:22.000000000 +0100
@@ -789,6 +792,18 @@
                                else
                                        return TRUE;
                        }
+#ifdef FLASH_OS_SUPPORT
+                        else if (SymNameMatches ("archive_start"))
+                          {
+                               if (Program->ResolveAllBuiltins && Program->MainSection)
+                                  {
+                                    SetToEntryPoint = TRUE;
+                                    NewValue = (OFFSET) ((unsigned long) (Program->MainSection->Size + 65535) & ~65535UL) - 0x02000;
+                                  }
+                               else
+                                  return TRUE;
+                          }
+#endif
                        else if (SymNameMatches ("kernel_export_table"))
                        {
                                BOOLEAN HasExports = FALSE;

PpHd (./5) :
Je suppose qu'il n'y a pas d'infrastructure pour simplifier le passage ABS32 -> ABS16. Tout est à faire ? Parce que sans çà, je ne commence pas à le faire.


En fait il y a des trucs. Reste à voir ce que je peux reprendre.

9

PpHd (./5) :
C'est pas simple.Je suppose qu'il n'y a pas d'infrastructure pour simplifier le passage ABS32 -> ABS16. Tout est à faire ? Parce que sans çà, je ne commence pas à le faire.

Il y a une infrastructure, celle de l'optimisation linker. smile
Il y a le code pour passer de ABS32 en REL16, passer en ABS16 ne devrait pas être beaucoup plus compliqué.
Pour PedroM, on doit pouvoir s'en sortir en jonglant avec les section (et désactiver le range cutting pour les sections définissant des tables). Mais je ne sais pas si c'est possible à l'heure actuelle (ie par section, ou par fichier ?).

C'est possible par fichier, mais pas dans les EDIs. (Il faut assembler avec des options différentes.) Le linker se rappelle des segments optimizables par range cutting ou pas.
PpHd (./7) :
Reste à voir si on la garantie que __ld_bss_size ne puisse pas être impair. Je crois que oui. Kevin ?

A priori si, il peut être impair.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

10

Kevin Kofler (./9) :
Il y a une infrastructure, celle de l'optimisation linker. smile.gif Il y a le code pour passer de ABS32 en REL16, passer en ABS16 ne devrait pas être beaucoup plus compliqué.


Oui. A voir.
Kevin Kofler (./9) :
A priori si, il peut être impair.

Il semblerait que l'assembleur ne puisse pas émettre autre chose que des sections BSS multiples de 4 pour a68k, de 2 pour GNU as.

11

C'est quoi les segment ?
Est-ce que a68k pourrait émettre des segment pour spécifier des zone non optimisables ?

12

PpHd (./10) :
Il semblerait que l'assembleur ne puisse pas émettre autre chose que des sections BSS multiples de 4 pour a68k, de 2 pour GNU as.

Notre GNU as est patché pour pouvoir émettre des sections de longueur impaire.
PpHd (./11) :
C'est quoi les segment ?

Les segments étaient jadis des sections, mais quand les sections ont été combinées (merged), les anciennes sections sont devenues des segments qui gardent l'information où le range-cutting est possible. Bref, c'est un concept interne au linker. Un ficher objet n'a que des sections quand il est importé.
Est-ce que a68k pourrait émettre des segment pour spécifier des zone non optimisables ?

Non, mais de toute façon ça ne résoudrait pas le problème des (x-y)/4, qui est qu'il n'existe pas de relogement pouvant exprimer ça. Nous avons rajouté de quoi exprimer x-y, mais pas (x-y)/n. Donc il faut assembler en un mode complètement différent (le mode "normal" où on n'émet pas de relogement pour x-y, pas le mode "all relocs" qui permet le range cutting). Le range cutting n'est pas possible sans ces relogements parce que x-y peut changer si on coupe entre x et y.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

13

mon grain de sel: pourquoi le bss est limité à 0x7FFF?

14

C'est le maximum pour l'adressage en abs.w (0xFFFF8000-0x00007FFF, la rangée 0xFFFF8000-0xFFFFFFFF est inutilisable sur TI sad).
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

15

justement, je comprends pas pourquoi on est obligés d'utiliser du abs.w

pff franchement un coup de gnu ld + le ldscript qui va bien, c'était moins compliqué ma méthode. Bon ok y'avait pas d'optim linker mais tant pis.

16

squalyl (./15) :
justement, je comprends pas pourquoi on est obligés d'utiliser du abs.w

Parce que ça prend 2 fois moins de place qu'un abs.l. smile
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

17

ah, ok. ça devrait être sélectionnable par une option, alors smile

18

Bah, l'idéal, c'est que le linker sait quelles variables BSS sont dans la rangée et optimise en abs.w les références à celles qui le sont et laisse les autres en abs.l automatiquement.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

19

ah, ok, donc la taille du bss est pas limitée à 32k alors? j'ai eu peur !

20

Bah, l'idéal != la solution la plus simple. wink
Et c'est moins de 32 KO parce qu'on ne peut pas commencer à 0 (il y a la table des vecteurs, la pile utilisateur, la pile superviseur, le LCD).
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

21

Kevin Kofler (./12) :
Notre GNU as est patché pour pouvoir émettre des sections de longueur impaire.

Pénible. Il faut que je rajoute un nouveau symbole.
[EDIT]: Pourtant, je n'arrive pas à le reproduire.
squalyl (./19) :
ah, ok, donc la taille du bss est pas limitée à 32k alors? j'ai eu peur !

Non.
Kevin Kofler (./18) :
Bah, l'idéal, c'est que le linker sait quelles variables BSS sont dans la rangée et optimise en abs.w les références à celles qui le sont et laisse les autres en abs.l automatiquement.

C'est ce que j'ai prévu.
squalyl (./15) :
justement, je comprends pas pourquoi on est obligés d'utiliser du abs.w

On n'est pas obbligé. C'est mieux.

22

oui, pigé, on passe à L pour les adresses plus grandes

this.prev: oué, je sais bien, justement, ça me paraissait étonnant.

23

Nouvelle version du patch avec un support partiel de abs32 --> abs16 pour les sections BSS.
diff -ur ld-tigcc.orig/bincode/fix_m68k.c ld-tigcc/bincode/fix_m68k.c
--- ld-tigcc.orig/bincode/fix_m68k.c	2005-02-14 07:25:28.000000000 +0100
+++ ld-tigcc/bincode/fix_m68k.c	2008-02-27 21:19:54.000000000 +0100
@@ -27,6 +27,10 @@
 
 #include <stdlib.h>
 
+#ifdef FLASH_OS_SUPPORT
+static void M68kFixBssAbs16 (RELOC *Reloc, OPTIMIZE_INFO *OptimizeInfo);
+#endif
+
 // Apply generic code fixes and optimizations to a section.
 void M68kFixCode (SECTION *Section)
 {
@@ -80,6 +84,12 @@
 					// Fix and possibly optimize or remove the reloc.
 					M68kFixReloc (Reloc, TargetDistance, OptimizeInfo);
 				}
+#ifdef FLASH_OS_SUPPORT
+                                // If we are for a flash os program, and the target is a BSS Section.
+                                if (Dest->Parent->Type == PT_FLASH_OS && Reloc->Target.Symbol
+                                    && Reloc->Target.Symbol->Parent == Reloc->Parent->Parent->BSSSection)
+                                  M68kFixBssAbs16 (Reloc, OptimizeInfo);
+#endif
 			}
 		}
 		
@@ -662,6 +672,193 @@
 	}
 }
 
+
+#ifdef FLASH_OS_SUPPORT
+static void M68kFixBssAbs16 (RELOC *Reloc, OPTIMIZE_INFO *OptimizeInfo)
+{
+  SECTION *Section = Reloc->Parent;
+  I1 *Data = Section->Data;
+  OFFSET RelocLocation = Reloc->Location;
+  OFFSET OpcodeLocation;
+  I1 *Opcode;
+
+  // Return if there is no data, the reloc is not optimizable or if the reloc size is not 4 bytes.
+  // If the section doesn't support the cut ranges, it doesn't worth the effort (we don't any reloc to emit).
+  if (!Data || Reloc->Unoptimizable || Reloc->Size != 4 || !Section->CanCutRanges)
+    return;
+  if (!(Reloc->Target.Symbol))
+    return;
+
+  // Test is the reloc is optimizable: the absolute address muse be < 2^15
+  OpcodeLocation  = GetLocationOffset (Reloc->Target.Symbol->Parent, &(Reloc->Target)) + Reloc->FixedOffset;
+  OpcodeLocation += (OFFSET) (OptimizeInfo->FlashOSBSSStart);
+  if (OpcodeLocation >= 0x7FFF)
+    return;
+
+  // Most opcodes are two bytes long, and the reloc follows immediately.
+  OpcodeLocation = RelocLocation - 2;
+  // Safety check before accessing the section data.
+  if (!IsBinaryDataRange (Section, OpcodeLocation, OpcodeLocation + 6, Reloc))
+    return;
+
+  Opcode = Data + OpcodeLocation;
+
+  // *** Move Optimization ***
+  // Optimize LEA(.L) var.L,reg into LEA(.w) var.W),reg.
+  if ((((Opcode [0] & M68K_LEA_ABS_MASK_0) == M68K_LEA_ABS_0) && ((Opcode [1] & M68K_LEA_ABS_MASK_1) == M68K_LEA_ABS_1))
+      // Optimize PEA(.L) var.L into PEA(.L) var.W(%PC).
+      || ((Opcode [0] == M68K_PEA_ABS_0) && (Opcode [1] == M68K_PEA_ABS_1))
+      // Optimize MOVE.x var.L,reg/(reg)/(reg)+ into
+      // MOVE.x var.W(%PC),reg/(reg)/(reg)+.
+      || (((Opcode [0] & M68K_MOVE_ABS_REG_MASK_0) == M68K_MOVE_ABS_REG_0) && ((Opcode [1] & M68K_MOVE_ABS_REG_MASK_1) == M68K_MOVE_ABS_REG_1)
+          && (!((Opcode [0] & M68K_MOVE_ABS_REG_INV_0_MASK_0) == M68K_MOVE_ABS_REG_INV_0_0))
+          && (!(((Opcode [0] & M68K_MOVE_ABS_REG_INV_1_MASK_0) == M68K_MOVE_ABS_REG_INV_1_0) && ((Opcode [1] & M68K_MOVE_ABS_REG_INV_1_MASK_1) == M68K_MOVE_ABS_REG_INV_1_1))))
+      // Optimize MOVE.x var.L,-(reg) into
+      // MOVE.x var.W(%PC),-(reg).
+      || (((Opcode [0] & M68K_MOVE_ABS_PREDEC_MASK_0) == M68K_MOVE_ABS_PREDEC_0) && ((Opcode [1] & M68K_MOVE_ABS_PREDEC_MASK_1) == M68K_MOVE_ABS_PREDEC_1)
+          && (!((Opcode [0] & M68K_MOVE_ABS_PREDEC_INV_0_MASK_0) == M68K_MOVE_ABS_PREDEC_INV_0_0))))
+    {
+      OptimizeInfo->OptimizeMovesResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeMoves)
+        {
+          // Turn the opcode into an abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Change the reloc to 2-byte absolute.
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 4, OpcodeLocation + 6, OptimizeInfo);
+        }
+      return;
+    }
+
+  // *** Test Optimization ***
+  // Optimize CMP.x var.L,reg into CMP.x var.W(%PC),reg.
+  if ((((Opcode [0] & M68K_CMP_ABS_REG_MASK_0) == M68K_CMP_ABS_REG_0) && ((Opcode [1] & M68K_CMP_ABS_REG_MASK_1) == M68K_CMP_ABS_REG_1)
+       && (!((Opcode [1] & M68K_CMP_ABS_REG_INV_0_MASK_1) == M68K_CMP_ABS_REG_INV_0_1)))
+      // Optimize BTST reg,var.L into BTST reg,var.W(%PC).
+      || (((Opcode [0] & M68K_BTST_REG_ABS_MASK_0) == M68K_BTST_REG_ABS_0) && ((Opcode [1] & M68K_BTST_REG_ABS_MASK_1) == M68K_BTST_REG_ABS_1)))
+    {
+      OptimizeInfo->OptimizeTestsResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeTests)
+        {
+          // Turn the opcode into a abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Change the reloc to 2-byte absolute.
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 4, OpcodeLocation + 6, OptimizeInfo);
+        }
+      return;
+    }
+
+  // *** Calculation Optimization ***
+  // Optimize ADD/SUB.x var.L,reg into
+  // ADD/SUB.x var.W(%PC),reg.
+  if ((((Opcode [0] & M68K_ADDSUB_ABS_REG_0_MASK_0) == M68K_ADDSUB_ABS_REG_0_0) && ((Opcode [1] & M68K_ADDSUB_ABS_REG_0_MASK_1) == M68K_ADDSUB_ABS_REG_0_1))
+      || (((Opcode [0] & M68K_ADDSUB_ABS_REG_1_MASK_0) == M68K_ADDSUB_ABS_REG_1_0) && ((Opcode [1] & M68K_ADDSUB_ABS_REG_1_MASK_1) == M68K_ADDSUB_ABS_REG_1_1))
+      // Optimize MUL/DIV.x var.L,reg into
+      // MUL/DIV.x var.W(%PC),reg.
+      || (((Opcode [0] & M68K_MULDIV_ABS_REG_MASK_0) == M68K_MULDIV_ABS_REG_0) && ((Opcode [1] & M68K_MULDIV_ABS_REG_MASK_1) == M68K_MULDIV_ABS_REG_1))
+      // Optimize AND/OR.x var.L,reg into
+      // AND/OR.x var.W(%PC),reg.
+      || (((Opcode [0] & M68K_ANDOR_ABS_REG_MASK_0) == M68K_ANDOR_ABS_REG_0) && ((Opcode [1] & M68K_ANDOR_ABS_REG_MASK_1) == M68K_ANDOR_ABS_REG_1)))
+    {
+      OptimizeInfo->OptimizeCalcsResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeCalcs)
+        {
+          // Turn the opcode into a abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Change the reloc to 2-byte .
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 4, OpcodeLocation + 6, OptimizeInfo);
+        }
+      return;
+    }
+
+  // Check opcodes of 8 bytes without prefix
+  if (!IsBinaryDataRange (Section, OpcodeLocation, OpcodeLocation + 8, Reloc))
+    return;
+
+  // Optimize MOVE.x var.L,ofs(reg) into
+  // MOVE.x var.W,ofs(reg)
+  // We cannot handle this above because of the
+  // offset, which comes after the reloc.
+  if (((Opcode [0] & M68K_MOVE_ABS_OFSREG_MASK_0) == M68K_MOVE_ABS_OFSREG_0) && ((Opcode [1] & M68K_MOVE_ABS_OFSREG_MASK_1) == M68K_MOVE_ABS_OFSREG_1)
+      && (!((Opcode [0] & M68K_MOVE_ABS_OFSREG_INV_0_MASK_0) == M68K_MOVE_ABS_OFSREG_INV_0_0)))
+    {
+      OptimizeInfo->OptimizeMovesResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeMoves)
+        {
+          // Turn the opcode into a abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Move the offset to the correct place.
+          Opcode [4] = Opcode [6];
+          Opcode [5] = Opcode [7];
+          // Change the reloc to 2-byte abs16.
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 6, OpcodeLocation + 8, OptimizeInfo);
+        }
+      return;
+    }
+
+  // Now Opcode are bigger (8 bytes)
+  OpcodeLocation = RelocLocation - 4;
+  Opcode = Data + OpcodeLocation;
+
+  if (!IsBinaryDataRange (Section, OpcodeLocation, OpcodeLocation + 8, Reloc))
+    return;
+
+  // Optimize MOVEM.x var.L,regs into
+  // MOVEM var.W,regs.
+  if (((Opcode [0] & M68K_MOVEM_ABS_REGS_MASK_0) == M68K_MOVEM_ABS_REGS_0) && ((Opcode [1] & M68K_MOVEM_ABS_REGS_MASK_1) == M68K_MOVEM_ABS_REGS_1))
+    {
+      OptimizeInfo->OptimizeMovesResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeMoves)
+        {
+          // Turn the opcode into a abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Change the reloc to 2-byte relative.
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 6, OpcodeLocation + 8, OptimizeInfo);
+        }
+    }
+
+  // Optimize BTST #num,var.L into
+  // BTST #num,var.W
+  if ((Opcode [0] == M68K_BTST_IMM_ABS_0) && (Opcode [1] == M68K_BTST_IMM_ABS_1) && (Opcode [2] == M68K_BTST_IMM_ABS_2))
+    {
+      OptimizeInfo->OptimizeTestsResult++;
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;
+      if (OptimizeInfo->OptimizeTests)
+        {
+          // Turn the opcode into a abs16 one.
+          M68K_MAKE_ABS16_OPCODE_1 (Opcode [1]);
+          // Change the reloc to 2-byte absolute.
+          Reloc->Size = 2;
+          // Cut or fill the gained space.
+          M68kCutOrFillRange (Section, OpcodeLocation + 6, OpcodeLocation + 8, OptimizeInfo);
+        }
+    }
+
+  // Nothing can be done
+  return;
+}
+#endif
+
 // Checks if a specific reloc might be optimizable. This is currently
 // limited to 4-bytes absolute relocs because that is the only case
 // this is needed for.
diff -ur ld-tigcc.orig/bincode/m68k.h ld-tigcc/bincode/m68k.h
--- ld-tigcc.orig/bincode/m68k.h	2004-12-23 00:12:09.000000000 +0100
+++ ld-tigcc/bincode/m68k.h	2008-02-27 19:56:44.000000000 +0100
@@ -37,6 +37,10 @@
 // Make a relative opcode out of an absolute one.
 #define M68K_MAKE_REL_OPCODE_1(Opcode_1) ((Opcode_1)++)
 
+// Make an absolute 16 bits opcode out of an absolute 32 bits address
+#define M68K_MAKE_ABS16_OPCODE_1(Opcode_1) ((Opcode_1)--)
+#define M68K_MAKE_ABS16_OPCODE_0(Opcode_0) ((Opcode_0)-=2)
+
 // *** General Branches ***
 
 // Opcode of the unconditional absolute JMP instruction.
diff -ur ld-tigcc.orig/export/exp_os.c ld-tigcc/export/exp_os.c
--- ld-tigcc.orig/export/exp_os.c	2004-12-23 00:12:09.000000000 +0100
+++ ld-tigcc/export/exp_os.c	2008-02-27 20:57:16.000000000 +0100
@@ -110,33 +110,43 @@
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);
+                        OFFSET TargetLocation = 0;
 			
 			// If this can be resolved to a calculator-dependent value, write the
 			// value into the section data.
 			if (EmitCalcBuiltinValue (Reloc, DestCalc, File, FileSize, DataStart))
 				continue;
 			
-			// We can only emit relocs with a target symbol in the same section.
 			if (!(Reloc->Target.Symbol))
 				FailWithError (CurFileName, "Unresolved reference to `%s'.", Reloc->Target.SymbolName);
-			if (Reloc->Target.Symbol->Parent != MainSection)
-				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);
-			
+
 			// We can only emit 4-byte absolute relocs.
-			if (Reloc->Relative || (Reloc->Size != 4))
+                        // Or 2-byte absolute relocs to the BSS Section.
+			if (Reloc->Relative || (Reloc->Size != 4 && (Reloc->Size != 2 || Reloc->Target.Symbol->Parent != Program->BSSSection)))
 				FailWithError (CurFileName, "Cannot emit %ld byte %s reloc to `%s'.", (long) Reloc->Size, Reloc->Relative ? "relative" : "absolute", Reloc->Target.SymbolName);
-			
-			{
-				OFFSET TargetLocation = GetLocationOffset (MainSection, &(Reloc->Target)) + Reloc->FixedOffset;
+
+                        // Check for BSS Section
+                        if (Program->OptimizeInfo->FlashOSBSSStart > 0
+                            && Reloc->Target.Symbol->Parent == Program->BSSSection) {
+                          TargetLocation = GetLocationOffset (Program->BSSSection, &(Reloc->Target)) + Reloc->FixedOffset;
+                          TargetLocation += (OFFSET) (Program->OptimizeInfo->FlashOSBSSStart);
+                          ExportSeek (File, DataStart + Reloc->Location);
+                          ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
+                          continue;
+                        }
+			// We can only emit relocs with a target symbol in the same section.
+			else if (Reloc->Target.Symbol->Parent != MainSection)
+				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);
+
+			TargetLocation = GetLocationOffset (MainSection, &(Reloc->Target)) + Reloc->FixedOffset;
 				
-				TargetLocation += (OFFSET) (ROMBase + 0x12000);
-				ExportSeek (File, DataStart + Reloc->Location);
-				ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
+                        TargetLocation += (OFFSET) (ROMBase + 0x12000);
+                        ExportSeek (File, DataStart + Reloc->Location);
+                        ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
 				
-				// Do not increase the statistics, since that would give a false
-				// impression that the relocation entries actually take up some
-				// space in the OS.
-			}
+                        // Do not increase the statistics, since that would give a false
+                        // impression that the relocation entries actually take up some
+                        // space in the OS.
 		}
 	}
 	
diff -ur ld-tigcc.orig/intrface.h ld-tigcc/intrface.h
--- ld-tigcc.orig/intrface.h	2005-03-31 06:12:52.000000000 +0200
+++ ld-tigcc/intrface.h	2008-02-26 20:42:06.000000000 +0100
@@ -52,6 +52,8 @@
 		CutRanges,          // Cut unneeded section ranges when optimizing.
 		ReorderSections,    // Reorder sections to shorten references.
 		MergeConstants;     // Merge constants and strings to avoid duplication.
+        B4
+                FlashOSBSSStart;    // Flash OS Start of BSS Section
 	SI4
 		ProgramSize,            // Size of the on-calc program variable.
 		DataSize,               // Size of the data variable.
diff -ur ld-tigcc.orig/main.c ld-tigcc/main.c
--- ld-tigcc.orig/main.c	2005-04-22 21:34:10.000000000 +0200
+++ ld-tigcc/main.c	2008-02-26 20:42:02.000000000 +0100
@@ -389,6 +389,8 @@
 #ifdef FLASH_OS_SUPPORT
 				if (Program.Type == PT_FLASH_OS)
 				{
+                                        if (OptInfo->FlashOSBSSStart > 0 && Program.BSSSection)
+                                          Program.BSSSection->Handled = TRUE;
 					// Flash OS export: merge startup and normal sections separately.
 					// The resulting two parts are merged later, padding the first
 					// part to the full 24 KB of the OS startup area (base 1)
diff -ur ld-tigcc.orig/main_opt.inc ld-tigcc/main_opt.inc
--- ld-tigcc.orig/main_opt.inc	2006-07-16 03:58:15.000000000 +0200
+++ ld-tigcc/main_opt.inc	2008-02-26 20:42:17.000000000 +0100
@@ -67,6 +67,7 @@
 					        "     --native             Link in TIGCC native mode\n"
 #ifdef FLASH_OS_SUPPORT
 					        "     --flash-os           Create (unsigned) Flash OS\n"
+						"     --flash-os-bss-start=<start> Start of the BSS Section in RAM (For Flash OS)\n"
 #endif /* FLASH_OS_SUPPORT */
 #ifdef FARGO_SUPPORT
 					        "     --fargo              Create Fargo II program\n"
@@ -131,6 +132,16 @@
 				{
 					Program.Type = PT_FLASH_OS;
 					Warning (NULL, "Flash OS support in TIGCC is experimental.");
+					OutputBin = TRUE;
+				}
+				else
+				if (!(strncmp (Arg, "flash-os-bss-start=", sizeof ("flash-os-bss-start=") - 1)))
+				{
+					char *End;
+					Arg += sizeof ("flash-os-bss-start=") - 1;
+					OptInfo->FlashOSBSSStart = strtoul (Arg, &End, 0);
+					if (End == Arg)
+					   Error (NULL, "Invalid number for flash-os-bss-start");
 				}
 				else
 #endif /* FLASH_OS_SUPPORT */
diff -ur ld-tigcc.orig/manip.c ld-tigcc/manip.c
--- ld-tigcc.orig/manip.c	2005-07-02 00:08:58.000000000 +0200
+++ ld-tigcc/manip.c	2008-02-26 20:28:56.000000000 +0100
@@ -955,7 +955,7 @@
 {
 	BOOLEAN MergeForward = FALSE;
 	SECTION *CurMergedSection = NULL, *Section, *NextSection;
-	
+
 	// For each section...
 	for (Section = GetLast (Program->Sections); Section; Section = NextSection)
 	{
diff -ur ld-tigcc.orig/special.c ld-tigcc/special.c
--- ld-tigcc.orig/special.c	2005-08-03 02:31:49.000000000 +0200
+++ ld-tigcc/special.c	2008-02-27 19:25:12.000000000 +0100
@@ -332,8 +332,11 @@
 		Result = Result && AddGlobalImport (Program, "__handle_constructors");
 	if (Program->Destructors.Start)
 		Result = Result && AddGlobalImport (Program, "__handle_destructors");
-	if (Program->BSSSection && Program->BSSSection->Initialized)
-		Result = Result && AddGlobalImport (Program, "__initialize_bss");
+	if (Program->BSSSection && Program->BSSSection->Initialized
+#ifdef FLASH_OS_SUPPORT
+            && Program->Type != PT_FLASH_OS
+#endif /* FLASH_OS_SUPPORT */
+          )	Result = Result && AddGlobalImport (Program, "__initialize_bss");
 	
 	// Handle BSS section if any.
 	if (Program->BSSSection && (!(Program->BSSSection->Handled)))
@@ -738,6 +741,16 @@
 				else
 					return TRUE;
 			}
+			else if (SymNameMatches ("bss_even_end"))
+			{
+				if (Program->BSSSection)
+				{
+					NewSymbol = Program->BSSSection->SectionSymbol;
+					NewTargetOffset = (OFFSET) ((unsigned long) (Program->BSSSection->Size + 1) & ~1UL);
+				}
+				else
+					return TRUE;
+			}
 			else if (SymNameMatches ("bss_size"))
 			{
 				if (Program->BSSSection)
@@ -789,6 +802,18 @@
 				else
 					return TRUE;
 			}
+#ifdef FLASH_OS_SUPPORT
+                        else if (SymNameMatches ("archive_start"))
+                          {
+				if (Program->ResolveAllBuiltins && Program->MainSection)
+                                  {
+                                    SetToEntryPoint = TRUE;
+                                    NewValue = (OFFSET) ((unsigned long) (Program->MainSection->Size + 65535) & ~65535UL) - 0x02000;
+                                  }
+				else
+                                  return TRUE;
+                          }
+#endif
 			else if (SymNameMatches ("kernel_export_table"))
 			{
 				BOOLEAN HasExports = FALSE;

Ca triple la taille du patch !

Limitations: je n'ai la détection de code que celle déjà supporté par ld-tigcc.
Il faut rajouter le support des instructions suivantes couic
move. reg/(reg)/(reg)+,abs.l
move. -(reg),abs.l
move. off(reg),abs.l
move.l #imm,var
clr var.l
tst var.l
cmpi #imm,abs.l
addi #imm,var.l
subi #imm,var.l
ori #imm,var.l
andi #imm,var.l
eori #imm,var.l
movem. ...,var.l
(Dites moi si j'en ai oublié).

Sous l'assembleur, serait-il possible de spécifier par section, l'option cut-ranges ?
Sorte de HandleSpecialSymbol mais par section ?

24

PpHd (./23) :
+ if (!Data || Reloc->Unoptimizable || Reloc->Size != 4 || !Section->CanCutRanges)

Il manque un test si on n'est pas dans un segment qui ne permet pas le range cutting (cf. la fonction CanCutRange).
+      if (OptimizeInfo->NearAssemblyResult >= 0)
+        OptimizeInfo->NearAssemblyResult += 2;

Le "near assembly" (switch -l) n'est pas possible pour adresser des BSS dans un FlashOS (ça essaie de faire du PC-relatif, pas du abs.w), donc ces lignes sont à supprimer.
-			if (Reloc->Target.Symbol->Parent != MainSection)
-				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);

Ce test n'est effectivement plus correct, mais au lieu de le supprimer complètement, il vaudrait mieux vérifier que la section est la section main ou BSS.
 					Warning (NULL, "Flash OS support in TIGCC is experimental.");
+					OutputBin = TRUE;

Non. Je sais bien que OutputBin est obligatoire actuellement, mais sortir des TIB sans OutputBin, ça va être embêtant quand on voudra rajouter le support pour les 89u/9xu/v2u. (ExtendeD m'a permis de réutiliser (sous GPL) le code son tib2xxu qui est livré avec FreeFlash, d'ailleurs, donc si tu veux rajouter ça aussi, tu peux partir de là. smile)
Limitations: je n'ai la détection de code que celle déjà supporté par ld-tigcc.
Il faut rajouter le support des instructions suivantes couic
move. reg/(reg)/(reg)+,abs.l
move. -(reg),abs.l
move. off(reg),abs.l
move.l #imm,var
clr var.l
tst var.l
cmpi #imm,abs.l
addi #imm,var.l
subi #imm,var.l
ori #imm,var.l
andi #imm,var.l
eori #imm,var.l
movem. ...,var.l(Dites moi si j'en ai oublié).

Attention, pour tous ceux-là, on a encore un problème: l'assembleur marque actuellement toutes les opérandes de destination comme non-optimisables, parce qu'elles ne peuvent pas être PC-relatives et parce que ça évite de boguer sur move.w #qqch_qui_est_aussi_un_opcode,lbl_destination. J'ai bien peur qu'il faudra rajouter encore un flag (qui dit "ceci est une opérande de destination") et gérer ce flag partout (le traîter comme non-optimisable pour le passage en PC-relatif, et n'activer les optimisations de source ou de destination dans ton code que quand il le faut).

Et il faudrait voir aussi comment gérer au mieux les MOVEM et les BTST (d'ailleurs je ne suis pas sûr que l'optimisation des BTST fonctionne actuellement, je pense que l'assembleur met ça en "non optimisable" parce que c'est une destination), parce que ça devrait être marqué aussi pour trouver l'opcode sans risquer un faux positif sur les 2 octets devant.

Le mieux est probablement de:
* dans les assembleurs, mettre un flag qui signifie "l'opcode est à -4 plutôt que -2" (si on n'est pas dans un opcode, mais par exemple dans un dc.l, on continue à mettre le flag unoptimizable)
* dans le linker:
- si le flag n'est pas mis, chercher à -2 et faire les tests sur les opcodes qui se trouvent à -2 uniquement,
- si le flag est mis, chercher à -4 et faire les tests sur les opcodes qui se trouvent à -4 uniquement.
Sous l'assembleur, serait-il possible de spécifier par section, l'option cut-ranges ?

Difficilement, parce qu'il faudrait aussi changer de mode dans l'assembleur (all relocs ou non) pour que ce soit vraiment utile.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

25

Kevin Kofler (./24) :
Il manque un test si on n'est pas dans un segment qui ne permet pas le range cutting (cf. la fonction CanCutRange).

Non. Il est fait plus loin si on détecte qu'on peut faire une modif.
Là c'est juste pour éviter de perdre du temps si on est sûr qu'on peut pas faire de cutrange.
Kevin Kofler (./24) :
Le "near assembly" (switch -l) n'est pas possible pour adresser des BSS dans un FlashOS (ça essaie de faire du PC-relatif, pas du abs.w), donc ces lignes sont à supprimer.

Ok.
Kevin Kofler (./24) :
Ce test n'est effectivement plus correct, mais au lieu de le supprimer complètement, il vaudrait mieux vérifier que la section est la section main ou BSS.

Il n'a pas été supprimé. Regarde mieux.
Kevin Kofler (./24) :
Non. Je sais bien que OutputBin est obligatoire actuellement, mais sortir des TIB sans OutputBin, ça va être embêtant quand on voudra rajouter le support pour les 89u/9xu/v2u. (ExtendeD m'a permis de réutiliser (sous GPL) le code son tib2xxu qui est livré avec FreeFlash, d'ailleurs, donc si tu veux rajouter ça aussi, tu peux partir de là. smile.gif )

C'est pas prévu pour 2048 ?
Kevin Kofler (./24) :
Attention, pour tous ceux-là, on a encore un problème: l'assembleur marque actuellement toutes les opérandes de destination comme non-optimisables, parce qu'elles ne peuvent pas être PC-relatives et parce que ça évite de boguer sur move.w #qqch_qui_est_aussi_un_opcode,lbl_destination. J'ai bien peur qu'il faudra rajouter encore un flag (qui dit "ceci est une opérande de destination") et gérer ce flag partout (le traîter comme non-optimisable pour le passage en PC-relatif, et n'activer les optimisations de source ou de destination dans ton code que quand il le faut).

Et il faudrait voir aussi comment gérer au mieux les MOVEM et les BTST (d'ailleurs je ne suis pas sûr que l'optimisation des BTST fonctionne actuellement, je pense que l'assembleur met ça en "non optimisable" parce que c'est une destination), parce que ça devrait être marqué aussi pour trouver l'opcode sans risquer un faux positif sur les 2 octets devant.

Le mieux est probablement de:
* dans les assembleurs, mettre un flag qui signifie "l'opcode est à -4 plutôt que -2" (si on n'est pas dans un opcode, mais par exemple dans un dc.l, on continue à mettre le flag unoptimizable)
* dans le linker:
- si le flag n'est pas mis, chercher à -2 et faire les tests sur les opcodes qui se trouvent à -2 uniquement, - si le flag est mis, chercher à -4 et faire les tests sur les opcodes qui se trouvent à -4 uniquement.

Arg. Tout çà à faire. Mais c'est probablement inévitable.

26

Arg sick

[pphd@localhost src]$ make
echo " dc.b" \"`date -u +"[%Y%m%d %k:%M]"`\" > version.h
tigcc -c -WA,-ic -WA,-i../../preos//src PedroM.asm Bss.asm -WA,-vTI89 
68000 Assembler - version 2.71.F3u (Feb 2, 2005)
Copyright 1985 by Brian R. Anderson
AmigaDOS conversion copyright 1991 by Charlie Gibbs.
Adapted for use with Fargo by David Ellsworth.
Bugfixes and additions by Julien Muchembled, Paul Froissart and Kevin Kofler

Assembling PedroM.asm

PASS 1 line 37494
PASS 2 line 37494
End of assembly - no errors were found.
Heap usage:  -w4095,296
Total hunk sizes:  1b870 code, 0 data, 0 BSS
68000 Assembler - version 2.71.F3u (Feb 2, 2005)
Copyright 1985 by Brian R. Anderson
AmigaDOS conversion copyright 1991 by Charlie Gibbs.
Adapted for use with Fargo by David Ellsworth.
Bugfixes and additions by Julien Muchembled, Paul Froissart and Kevin Kofler

Assembling Bss.asm

PASS 1 line 930
PASS 2 line 930
End of assembly - no errors were found.
Heap usage:  -w4095,264
Total hunk sizes:  0 code, 0 data, 27f8 BSS
tigcc -v --flash-os --outputbin --flash-os-bss-start=0x5B00 PedroM.o
tigcc: /home/pphd/tigcc/bin/ld-tigcc -v --flash-os PedroM.o /home/pphd/tigcc/lib/flashos.a -o PedroM --outputbin
Warning: Flash OS support in TIGCC is experimental.
PedroM.o: Error: Unresolved reference to `BSSSectionStart'.
make: *** [pedrom-89] Error 1

Les deux fichiers sont compilés, mais tigcc n'en passe qu'un au linkeur !

[pphd@localhost src]$ /home/pphd/tigcc/bin/ld-tigcc -v --flash-os PedroM.o Bss.o /home/pphd/tigcc/lib/flashos.a -o PedroM --outputbin
Warning: Flash OS support in TIGCC is experimental.
Bss.o: Error: Symbol import/export hunk without context.
PedroM.o: Error: Unresolved reference to `BSSSectionStart'.

On passe les 2 à la main, et poum, une erreur système de ld-tigcc !

Le fichier qui pose problème Bss.asm ne possède qu'une section BSS qu'il exporte.
Si j'essaye de le compiler :
[pphd@localhost src]$ a68k -g Bss.asm -i../../preos/src/
68000 Assembler - version 2.71.F3u (Feb 2, 2005)
Copyright 1985 by Brian R. Anderson
AmigaDOS conversion copyright 1991 by Charlie Gibbs.
Adapted for use with Fargo by David Ellsworth.
Bugfixes and additions by Julien Muchembled, Paul Froissart and Kevin Kofler

Assembling Bss.asm

PASS 1 line Segmentation fault

Bonheur...

Le fichier Bss.asm:
;
; PedroM - Operating System for Ti-89/Ti-92+/V200.
; Copyright (C) 2008 Patrick Pelissier
;
; This program is free software ; you can redistribute it and/or modify it under the
; terms of the GNU General Public License as published by the Free Software Foundation;
; either version 2 of the License, or (at your option) any later version. 
; 
; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
; See the GNU General Public License for more details. 
; 
; You should have received a copy of the GNU General Public License along with this program;
; if not, write to the 
; Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

	;; Define the BSS Section for PedroM.
DefineBSSSection set 1

	section ".text"
        xdef	BSSSectionStart
	
	include	"Const.h"		; Constant and Variables.


Le fichier Const.h est celui de PedroM modulo le fait qui inclue Vars.h et kheader.h à la fin.
Vars.h a été légèrement modifié:
;
; PedroM - Operating System for Ti-89/Ti-92+/V200/Titanium.
; Copyright (C) 2003, 2005-2008 Patrick Pelissier
;
; This program is free software ; you can redistribute it and/or modify it under the
; terms of the GNU General Public License as published by the Free Software Foundation;
; either version 2 of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
; See the GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License along with this program;
; if not, write to the
; Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

; System Vars (Globals).

     ifd  DefineBSSSection
     BSS
BSSSectionStart:
     ;; Reserve some place in the BSS Section
rs   MACRO
\1   ds.b \2
     ENDM
     endc

     ifnd  DefineBSSSection
data_start_offset       set	$4C00+$F00
data_global_offset	set	data_start_offset
rs	MACRO
\1	EQU	data_global_offset
data_global_offset	set	data_global_offset+\2
	ENDM
     endc

     ;; Set one data :
     ;;	rs name,data_len

	rs	FloatReg1,FLOAT.sizeof			;// Float register : it is used mainly by internal Floatting Point functions to overides the lack of FPU
	rs	FloatReg2,FLOAT.sizeof
	rs	FloatReg3,FLOAT.sizeof
	rs	FloatReg4,FLOAT.sizeof
	rs	FloatPreCalculMultTab,FLOAT.sizeof*10	;// Table used by FloatMult/FLoatDivide functions to precalculted the multiplication of a floatr by the finger 0, 1, 2 ... 9.
[...]


Des idées ?

27

PpHd (./26) :
tigcc -v --flash-os --outputbin --flash-os-bss-start=0x5B00 PedroM.o
tigcc: /home/pphd/tigcc/bin/ld-tigcc -v --flash-os PedroM.o /home/pphd/tigcc/lib/flashos.a -o PedroM --outputbin

[...]Les deux fichiers sont compilés, mais tigcc n'en passe qu'un au linkeur !

Parce que ton makefile lui passe seulement ce fichier. roll Tu n'as rajouté le deuxième fichier que pour tigcc -c.
Bss.o: Error: Symbol import/export hunk without context.

Visiblement, le fichier que pond A68k n'est pas valide. Je pense qu'on n'a pas le droit de créer une section vide (la section ".text" dans ton Bss.asm).
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

28

Patch pour tigcc :
--- tigcc.c~    2006-07-16 05:05:48.000000000 +0200
+++ tigcc.c     2008-02-29 20:46:05.000000000 +0100
@@ -223,7 +223,7 @@
   } else if (!strcmp("--fargo", cur_arg)) {
     fargo = TRUE;
     ld_argv[ld_argc++] = cur_arg;
-  } else if (!strcmp("--flash-os", cur_arg)) {
+  } else if (!strncmp("--flash-os", cur_arg, sizeof ("--flash-os")-1)) {
     flashos = TRUE;
     ld_argv[ld_argc++] = cur_arg;
   } else if (!strcmp("--cut-ranges", cur_arg)) {


Un truc étrange m'est survenu.
Pour le code suivant :
          section ".st1"
_ti89   xdef    _ti89
        lea     (toto).w,a0
        bra     *
        sne     (tutu).w
        
        section ".text"
        bra     *

        BSS
toto:   ds.b    4
tutu:   dc.l    0

J'ai droit à des relogements relatifs:
*** DUMP 0 ***
Section
  File: Test.o
  Code
   Test.o .st1: (local)
     0x000000: 41 F8
     0x000002: <2B: Test.o .bss (->) (rel)>
     0x000004: 60 FE 56 F8
     0x000008: <2B: Test.o .bss (->)+4 (rel)>
     0x00000A: 4E 71
Section
  File: Test.o
  Code
   Test.o .text: (local)
     0x000000: 60 FE 4E 71
Section
  File: Test.o
  Data
   Test.o .bss: (local)
     0x000000: 00 00 00 00 00 00 00 00


Est-ce normal ?

29

À ma connaissance, les relogements en abs.w ne sont pas du tout gérés dans les assembleurs.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

30

Bon ca fonctionne en BSS avec un super hack sauvage.
Reste à découper en plein de .asm et laisser le linkeur faire son boulôt.
Je tomberais sur plein d'autres erreurs à mon avis, mais bon.

KK: C'est bon pour moi. Tu peux réintégrer. Tu veux un patch ou ce qui a été posté te suffit ?