Skip to contentSkip to conversation

remove bsd asm helper functions

PATCH In review phcoder 1 participant 3 messages Feb 11, 2009 – Mar 12, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

PATCH 1/1 remove bsd asm helper functions

Hello. Asm helper functions for bsd aren't really needed. Actually BSD entry point may be called directly as cdecl function. With this approach theese helper functions don't take place in kernel anymore. Tested with freebsd, openbsd and netbsd. However my tests were limited to launching kernel and see if it complains about not being able to mount root. Can someone test it with complete system? Thanks
Vladimir 'phcoder' Serbinenko

i386/loader.S +0 -23
Index: kern/i386/loader.S
===================================================================
@@ -117,23 +117,0 @@
-/*
- * Use cdecl calling convention for *BSD kernels.
- */
-
-FUNCTION(grub_unix_real_boot)
-
-        call    EXT_C(grub_dl_unload_all)
-        call    EXT_C(grub_stop_floppy)
-
-	/* Interrupts should be disabled.  */
-        cli
-
-	/* Discard `grub_unix_real_boot' return address.  */
-        popl    %eax
-
-        /* Fetch `entry' address ...  */
-        popl	%eax
-
-        /*
-         * ... and put our return address in its place. The kernel will
-         * ignore it, but it expects %esp to point to it.
-         */
-        call	*%eax
grub/i386/loader.h +1 -3
Index: include/grub/i386/loader.h
===================================================================
@@ -22,7 +22,6 @@
 #include <grub/types.h>
 #include <grub/err.h>
 #include <grub/symbol.h>
-#include <grub/multiboot.h>
 
 extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);
 extern char *EXPORT_VAR(grub_linux_tmp_addr);
@@ -33,22 +32,21 @@
 void EXPORT_FUNC(grub_multiboot2_real_boot) (grub_addr_t entry,
                                              struct grub_multiboot_info *mbi)
      __attribute__ ((noreturn));
-void EXPORT_FUNC(grub_unix_real_boot) (grub_addr_t entry, ...)
-     __attribute__ ((cdecl,noreturn));
 
 extern grub_addr_t EXPORT_VAR(grub_multiboot_payload_orig);
 extern grub_addr_t EXPORT_VAR(grub_multiboot_payload_dest);
 extern grub_size_t EXPORT_VAR(grub_multiboot_payload_size);
 extern grub_uint32_t EXPORT_VAR(grub_multiboot_payload_entry_offset);
 
 /* It is necessary to export these functions, because normal mode commands
    reuse rescue mode commands.  */
 void grub_rescue_cmd_linux (int argc, char *argv[]);
 void grub_rescue_cmd_initrd (int argc, char *argv[]);
 
 extern grub_uint8_t EXPORT_VAR(grub_multiboot_forward_relocator);
 extern grub_uint8_t EXPORT_VAR(grub_multiboot_forward_relocator_end);
 extern grub_uint8_t EXPORT_VAR(grub_multiboot_backward_relocator);
 extern grub_uint8_t EXPORT_VAR(grub_multiboot_backward_relocator_end);
+void EXPORT_FUNC(grub_stop_floppy) (void);
 
 #define RELOCATOR_SIZEOF(x)	(&grub_multiboot_##x##_relocator_end - &grub_multiboot_##x##_relocator)

#endif /* ! GRUB_LOADER_CPU_HEADER */

i386/bsd.c +30 -7
Index: loader/i386/bsd.c
===================================================================
@@ -302,9 +302,17 @@
 
   bi.bi_kernend = kern_end;
 
-  grub_unix_real_boot (entry, bootflags | FREEBSD_RB_BOOTINFO, bootdev,
-		       0, 0, 0, &bi, bi.bi_modulep, kern_end);
+  grub_stop_floppy ();
 
+  asm volatile ("cli");
+
+  ((void (* __attribute__ ((cdecl,regparm (0))))  
+    (grub_uint32_t, grub_uint32_t, grub_uint32_t, grub_uint32_t, 
+     grub_uint32_t, struct grub_freebsd_bootinfo *,
+     grub_addr_t, grub_addr_t))entry)
+    (bootflags | FREEBSD_RB_BOOTINFO, bootdev,
+     0, 0, 0, &bi, bi.bi_modulep, kern_end);
+  
   /* Not reached.  */
   return GRUB_ERR_NONE;
 }
@@ -348,10 +356,18 @@
   bootdev = (OPENBSD_B_DEVMAGIC + (unit << OPENBSD_B_UNITSHIFT) +
 	     (part << OPENBSD_B_PARTSHIFT));
 
-  grub_unix_real_boot (entry, bootflags, bootdev, OPENBSD_BOOTARG_APIVER,
-		       0, grub_upper_mem >> 10, grub_lower_mem >> 10,
-		       (char *) pa - buf, buf);
+  grub_stop_floppy ();
 
+  asm volatile ("cli");
+
+  ((void (* __attribute__ ((cdecl,regparm (0))))  
+    (grub_uint32_t, grub_uint32_t, grub_uint32_t, grub_uint32_t, 
+     grub_uint32_t, grub_uint32_t,
+     grub_uint32_t, char *)) entry) 
+    (bootflags, bootdev, OPENBSD_BOOTARG_APIVER,
+     0, grub_upper_mem >> 10, grub_lower_mem >> 10,
+     (char *) pa - buf, buf);
+
   /* Not reached.  */
   return GRUB_ERR_NONE;
 }
@@ -376,9 +392,16 @@
   bootinfo->bi_count = 1;
   bootinfo->bi_data[0] = rootdev;
 
-  grub_unix_real_boot (entry, bootflags, 0, bootinfo,
-		       0, grub_upper_mem >> 10, grub_lower_mem >> 10);
+  grub_stop_floppy ();
 
+  asm volatile ("cli");
+
+  ((void (* __attribute__ ((cdecl,regparm (0))))  
+    (grub_uint32_t, grub_uint32_t, struct grub_netbsd_bootinfo *, 
+     grub_uint32_t, grub_uint32_t, grub_uint32_t)) entry) 
+    (bootflags, 0, bootinfo,
+     0, grub_upper_mem >> 10, grub_lower_mem >> 10);
+
   /* Not reached.  */
   return GRUB_ERR_NONE;
 }
author
#1 lore raw

Sorry, forgot changelog entry. Here it is:
2009-02-11 Vladimir Serbinenko <[email protected]>

Move BSD helper out of kernel

* conf/i386-pc.rmk: Add loader/i386/bsd_helper.S to _bsd.mod
* kern/i386/loader.S: Removed BSD helpers
* include/grub/i386/loader.h: Removed declaration of grub_unix_real_boot
* loader/i386/bsd.c (grub_freebsd_boot): Replaced call to grub_unix_real_boot by direct call of kernel (grub_netbsd_boot): Likewise
(grub_openbsd_boot): Likewise

Quoted 4 lines · phcoder

Hello. Asm helper functions for bsd aren't really needed. Actually BSD entry point may be called directly as cdecl function. With this approach theese helper functions don't take place in kernel anymore. Tested with freebsd, openbsd and netbsd. However my tests were limited to launching kernel and see if it complains about not being able to mount root. Can someone test it with complete system? Thanks
Vladimir 'phcoder' Serbinenko

author
#2 lore raw

Hello. Now I noticed that the helper are still necessary when booting i386 kernel on efi-x86_64. I would like this code to be uniform accross i386 branches so please don't commit this patch it will be soon superseed by my next work

Quoted 20 lines · phcoder

Sorry, forgot changelog entry. Here it is:
2009-02-11 Vladimir Serbinenko <[email protected]>

Move BSD helper out of kernel

* conf/i386-pc.rmk: Add loader/i386/bsd_helper.S to _bsd.mod
* kern/i386/loader.S: Removed BSD helpers
* include/grub/i386/loader.h: Removed declaration of grub_unix_real_boot
* loader/i386/bsd.c (grub_freebsd_boot): Replaced call to grub_unix_real_boot by direct call of kernel (grub_netbsd_boot): Likewise
(grub_openbsd_boot): Likewise

Quoted 4 lines · phcoder

Hello. Asm helper functions for bsd aren't really needed. Actually BSD entry point may be called directly as cdecl function. With this approach theese helper functions don't take place in kernel anymore. Tested with freebsd, openbsd and netbsd. However my tests were limited to launching kernel and see if it complains about not being able to mount root. Can someone test it with complete system? Thanks
Vladimir 'phcoder' Serbinenko

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko