Hi,
some time ago, we decided that stage2 should share code with stage0 whenever possible. I have investigated the current situation and we could do much better. Example analysis for the qemu target in its current revision follows:
Shared functions/symbols: die gdt_limit gdtptr get_option_table post_code printk rtc_init sprintf
Duplicated functions: size name 0000001a delay 0000001a mdelay 0000000e udelay 00000027 memcmp 0000000f memcpy 000000d6 memcpy_helper 00000021 memmove 00000013 memset 00000007 rawpnp_enter_ext_func_mode 00000006 rawpnp_exit_ext_func_mode 00000015 rawpnp_set_enable 00000029 rawpnp_set_iobase 00000012 rawpnp_set_logical_device 0000000e rawpnp_write_config
We waste a total of 493 bytes.
Patch for *delay and mem* functions follows, saving 386 bytes.
Regards, Carl-Daniel
To reduce code duplication, make sure STAGE2_*OBJ does not contain any object already mentioned in STAGE0_*_OBJ. Specifically, remove mem.o, delay.o, udelay_io.o from STAGE2_*OBJ. This saves 386 bytes in stage2 (~240 bytes after LZMA compression).
In the future, automatically removing objects from STAGE2_OBJ which are already included in STAGE0_OBJ will be the way to go.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
--- Index: LinuxBIOSv3/arch/x86/Makefile =================================================================== --- LinuxBIOSv3/arch/x86/Makefile (revision 512) +++ LinuxBIOSv3/arch/x86/Makefile (working copy) @@ -167,11 +167,13 @@ # Where should it be built, maybe in device/? # # TODO: This should be compressed with the default compressor. +# To reduce code duplication, always make sure STAGE2_LIB_OBJ does not contain +# any object already mentioned in STAGE0_LIB_OBJ. #
-STAGE2_LIB_OBJ = stage2.o clog2.o mem.o tables.o delay.o compute_ip_checksum.o +STAGE2_LIB_OBJ = stage2.o clog2.o tables.o compute_ip_checksum.o
-STAGE2_ARCH_X86_OBJ = archtables.o linuxbios_table.o udelay_io.o +STAGE2_ARCH_X86_OBJ = archtables.o linuxbios_table.o STAGE2_ARCH_X86_OBJ += pci_ops_auto.o pci_ops_conf1.o pci_ops_conf2.o STAGE2_ARCH_X86_OBJ += keyboard.o i8259.o isa-dma.o
On 21.11.2007 15:39, Carl-Daniel Hailfinger wrote: [explanation snipped, see original post]
To reduce code duplication, make sure STAGE2_*OBJ does not contain any object already mentioned in STAGE0_*_OBJ. Specifically, remove mem.o, delay.o, udelay_io.o from STAGE2_*OBJ. This saves 386 bytes in stage2 (~240 bytes after LZMA compression).
In the future, automatically removing objects from STAGE2_OBJ which are already included in STAGE0_OBJ will be the way to go.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Opinions?
Regards, Carl-Daniel
Carl-Daniel Hailfinger schrieb:
On 21.11.2007 15:39, Carl-Daniel Hailfinger wrote: [explanation snipped, see original post]
To reduce code duplication, make sure STAGE2_*OBJ does not contain any object already mentioned in STAGE0_*_OBJ. Specifically, remove mem.o, delay.o, udelay_io.o from STAGE2_*OBJ. This saves 386 bytes in stage2 (~240 bytes after LZMA compression).
In the future, automatically removing objects from STAGE2_OBJ which are already included in STAGE0_OBJ will be the way to go.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Opinions?
Yes. We should think about this again when we sorted out the inter-stage call issues.
Stefan
On 25.11.2007 16:26, Stefan Reinauer wrote:
Carl-Daniel Hailfinger schrieb:
On 21.11.2007 15:39, Carl-Daniel Hailfinger wrote: [explanation snipped, see original post]
To reduce code duplication, make sure STAGE2_*OBJ does not contain any object already mentioned in STAGE0_*_OBJ. Specifically, remove mem.o, delay.o, udelay_io.o from STAGE2_*OBJ. This saves 386 bytes in stage2 (~240 bytes after LZMA compression).
In the future, automatically removing objects from STAGE2_OBJ which are already included in STAGE0_OBJ will be the way to go.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Opinions?
Yes. We should think about this again when we sorted out the inter-stage call issues.
Now that these issues are mostly solved, can we consider an improved patch to solve code duplication?
To reduce code duplication, make sure STAGE2_OBJ does not contain any object already mentioned in STAGE0_OBJ. This saves 386 bytes in qemu stage2 (~240 bytes after LZMA compression).
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile =================================================================== --- LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Revision 529) +++ LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Arbeitskopie) @@ -198,11 +198,16 @@ STAGE2_OBJ += $(obj)/util/x86emu/libx86emu.a $(LIBGCC_FILE_NAME) endif
-$(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ) +# To reduce code duplication, always make sure STAGE2_OBJ does not contain +# any object from STAGE0_OBJ. + +STAGE2_OBJ_NEEDED = $(filter-out $(STAGE0_OBJ), $(STAGE2_OBJ)) + +$(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ_NEEDED) $(Q)# leave a .o with full symbols in it for debugging. $(Q)printf " LD $(subst $(shell pwd)/,,$(@))\n" $(Q)$(LD) -R $(obj)/stage0.o -Ttext 0x1000 --entry=stage2 \ - -o $(obj)/linuxbios.stage2.o $(STAGE2_OBJ) + -o $(obj)/linuxbios.stage2.o $(STAGE2_OBJ_NEEDED) $(Q)$(NM) $(obj)/linuxbios.stage2.o | sort -u > $(obj)/linuxbios.stage2.map
#
Comments? This has been sitting in my tree for a while.
Regards, Carl-Daniel
On 28.11.2007 01:04, Carl-Daniel Hailfinger wrote:
To reduce code duplication, make sure STAGE2_OBJ does not contain any object already mentioned in STAGE0_OBJ. This saves 386 bytes in qemu stage2 (~240 bytes after LZMA compression).
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile
--- LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Revision 529) +++ LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Arbeitskopie) @@ -198,11 +198,16 @@ STAGE2_OBJ += $(obj)/util/x86emu/libx86emu.a $(LIBGCC_FILE_NAME) endif
-$(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ) +# To reduce code duplication, always make sure STAGE2_OBJ does not contain +# any object from STAGE0_OBJ.
+STAGE2_OBJ_NEEDED = $(filter-out $(STAGE0_OBJ), $(STAGE2_OBJ))
+$(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ_NEEDED) $(Q)# leave a .o with full symbols in it for debugging. $(Q)printf " LD $(subst $(shell pwd)/,,$(@))\n" $(Q)$(LD) -R $(obj)/stage0.o -Ttext 0x1000 --entry=stage2 \
-o $(obj)/linuxbios.stage2.o $(STAGE2_OBJ)
$(Q)$(NM) $(obj)/linuxbios.stage2.o | sort -u > $(obj)/linuxbios.stage2.map-o $(obj)/linuxbios.stage2.o $(STAGE2_OBJ_NEEDED)
#
To reduce code duplication, make sure STAGE2_OBJ does not contain any object already mentioned in STAGE0_OBJ. This saves 386 bytes in qemu stage2 (~240 bytes after LZMA compression).
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile =================================================================== --- LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Revision 539) +++ LinuxBIOSv3-filteroutduplicatedshared/arch/x86/Makefile (Arbeitskopie) @@ -198,11 +198,16 @@ STAGE2_OBJ += $(obj)/util/x86emu/libx86emu.a $(LIBGCC_FILE_NAME) endif
-$(obj)/linuxbios.stage2 $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ) +# To reduce code duplication, always make sure STAGE2_OBJ does not contain +# any object from STAGE0_OBJ. + +STAGE2_OBJ_NEEDED = $(filter-out $(STAGE0_OBJ), $(STAGE2_OBJ)) + +$(obj)/linuxbios.stage2 $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ_NEEDED) $(Q)# leave a .o with full symbols in it for debugging. $(Q)printf " LD $(subst $(shell pwd)/,,$(@))\n" $(Q)$(LD) -R $(obj)/stage0.o -Ttext 0x1000 --entry=stage2 \ - -o $(obj)/linuxbios.stage2 $(STAGE2_OBJ) + -o $(obj)/linuxbios.stage2 $(STAGE2_OBJ_NEEDED) $(Q)$(NM) $(obj)/linuxbios.stage2 | sort -u > $(obj)/linuxbios.stage2.map
#
On Wed, Dec 05, 2007 at 02:56:26AM +0100, Carl-Daniel Hailfinger wrote:
To reduce code duplication, make sure STAGE2_OBJ does not contain any object already mentioned in STAGE0_OBJ. This saves 386 bytes in qemu stage2 (~240 bytes after LZMA compression).
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Peter Stuge peter@stuge.se
On 05.12.2007 04:59, Peter Stuge wrote:
On Wed, Dec 05, 2007 at 02:56:26AM +0100, Carl-Daniel Hailfinger wrote:
To reduce code duplication, make sure STAGE2_OBJ does not contain any object already mentioned in STAGE0_OBJ. This saves 386 bytes in qemu stage2 (~240 bytes after LZMA compression).
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Peter Stuge peter@stuge.se
Thanks, r540.
Regards, Carl-Daniel