Fermer2
PpHdLe 26/02/2008 à 21:13
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)))