+static int copy_gd_to_ram(void)
+{
+ gd_t *ram_gd;
+
+ /*
+ * Global data is still in temporary memory (the CPU cache).
+ * calculate_relocation_address() has set gd->new_gd_addr to
+ * where the global data lives in RAM but getting it there
+ * safely is a bit tricky due to the 'F-Segment Hack' that
+ * we need to use for x86
+ */
+ ram_gd = (gd_t *)gd->new_gd_addr;
+ memcpy((void *)ram_gd, gd, sizeof(gd_t));
+
+ /*
+ * Reload the Global Descriptor Table so FS points to the
+ * in-RAM copy of Global Data (calculate_relocation_address()
+ * has already calculated the in-RAM location of the GDT)
+ */
+ ram_gd->gd_addr = (ulong)ram_gd;
+ init_gd(ram_gd, (u64 *)gd->gdt_addr);
+
+ return 0;
+}
+