[rom_ext, bare_metal] Move global pointer init to start

Signed-off-by: Alphan Ulusoy <alphan@google.com>
diff --git a/sw/device/silicon_creator/rom_ext/rom_ext_start.S b/sw/device/silicon_creator/rom_ext/rom_ext_start.S
index 78d8f90..6ffc09e 100644
--- a/sw/device/silicon_creator/rom_ext/rom_ext_start.S
+++ b/sw/device/silicon_creator/rom_ext/rom_ext_start.S
@@ -101,14 +101,6 @@
   .section .crt, "ax"
 
   /**
-   * Linker Relaxation is disabled until `__global_pointer$` is setup, below,
-   * because otherwise some sequences may be turned into gp-relative sequences,
-   * which is incorrect when `gp` is not initialized.
-   */
-  .option push
-  .option norelax
-
-  /**
    * Entry point.
    *
    * This symbol is jumped to from `rom_boot` using the `entry_point` field
@@ -119,6 +111,18 @@
   .type _rom_ext_start_boot, @function
 _rom_ext_start_boot:
   /**
+   * Set up the global pointer `gp`.
+   *
+   * Linker relaxations are disabled until the global pointer is setup below,
+   * because otherwise some sequences may be turned into `gp`-relative
+   * sequences, which is incorrect when `gp` is not initialized.
+   */
+  .option push
+  .option norelax
+  la gp, __global_pointer$
+  .option pop
+
+  /**
    * Disable Interrupts.
    *
    * We cannot disable exceptions, or Ibex's non-maskable interrupts (interrupt
@@ -198,17 +202,6 @@
   li a7, 0x0
 
   /**
-   * Setup global pointer.
-   *
-   * This requires that we disable linker relaxations, or it will be relaxed to
-   * `mv gp, gp`, so we disabled relaxations for all of `_rom_start_boot`.
-   */
-  la gp, __global_pointer$
-
-  // Re-enable linker relaxation.
-  .option pop
-
-  /**
    * Jump to C Code
    */
   tail rom_ext_main
diff --git a/sw/device/silicon_owner/bare_metal/bare_metal_start.S b/sw/device/silicon_owner/bare_metal/bare_metal_start.S
index f007ff6..da46680 100644
--- a/sw/device/silicon_owner/bare_metal/bare_metal_start.S
+++ b/sw/device/silicon_owner/bare_metal/bare_metal_start.S
@@ -101,14 +101,6 @@
   .section .crt, "ax"
 
   /**
-   * Linker Relaxation is disabled until `__global_pointer$` is setup, below,
-   * because otherwise some sequences may be turned into gp-relative sequences,
-   * which is incorrect when `gp` is not initialized.
-   */
-  .option push
-  .option norelax
-
-  /**
    * Entry point.
    */
   .balign 4
@@ -116,6 +108,18 @@
   .type _start_boot, @function
 _start_boot:
   /**
+   * Set up the global pointer `gp`.
+   *
+   * Linker relaxations are disabled until the global pointer is setup below,
+   * because otherwise some sequences may be turned into `gp`-relative
+   * sequences, which is incorrect when `gp` is not initialized.
+   */
+  .option push
+  .option norelax
+  la gp, __global_pointer$
+  .option pop
+
+  /**
    * Disable Interrupts.
    *
    * We cannot disable exceptions, or Ibex's non-maskable interrupts (interrupt
@@ -195,17 +199,6 @@
   li a7, 0x0
 
   /**
-   * Setup global pointer.
-   *
-   * This requires that we disable linker relaxations, or it will be relaxed to
-   * `mv gp, gp`, so we disabled relaxations for all of `_rom_start_boot`.
-   */
-  la gp, __global_pointer$
-
-  // Re-enable linker relaxation.
-  .option pop
-
-  /**
    * Jump to C Code
    */
   tail bare_metal_main