From: Sergey Vlasov <vsu@altlinux.ru>
To: ALT Devel discussion list <devel@lists.altlinux.org>
Subject: Re: [devel] GRUB и сородичи
Date: Thu, 21 Dec 2006 19:13:15 +0300
Message-ID: <20061221161315.GH13343@master.mivlgu.local> (raw)
In-Reply-To: <20061221154657.GB10842@basalt.office.altlinux.org>
[-- Attachment #1: Type: text/plain, Size: 11880 bytes --]
On Thu, Dec 21, 2006 at 06:46:57PM +0300, Dmitry V. Levin wrote:
> On Thu, Dec 21, 2006 at 06:42:43PM +0300, Sergey Vlasov wrote:
> > On Thu, Dec 21, 2006 at 06:15:04PM +0300, Epiphanov Sergei wrote:
> > > > > Думал, можно обойтись малой кровью. :( Интересно, а что мешает
> > > > > попробовать собрать grub без этого ключа? Программирование на asm?
> > > >
> > > > Сергей сказал, что там есть i386 asm.
> > >
> > > Вот только насколько оно привязано именно к i386 и к 32-битному полю?..
> > > Неужели так жёстко, что сборка под 64-бит рушит сам процесс работы grub?
> > > Жаль, не на чем проверить...
> >
> > Собственно загрузчик (/boot/grub/stage*) всегда собирается с -m32, и
> > с этой частью особых проблем нет (кроме необходимости костылей в
> > configure для объезда невозможности линковки с -m32, а также
> > исправления нескольких ошибок в Makefile.am).
>
> Т.е. там не нужен -m32?
Как раз нужен - проблема в том, что с нашим gcc не проходят тесты в
configure из-за того, что делается попытка собрать бинарник с -m32;
приходится обходить это хаками.
--- grub-0.97/stage2/Makefile.am.alt-x86_64-m32 2006-07-21 11:02:14 +0400
+++ grub-0.97/stage2/Makefile.am 2006-07-21 11:09:07 +0400
@@ -55,11 +55,11 @@
endif
MOSTLYCLEANFILES = $(noinst_PROGRAMS)
-PRE_STAGE2_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
-START_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
-NBLOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,0
-PXELOADER_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
-START_ELTORITO_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
+PRE_STAGE2_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
+START_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
+NBLOADER_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,0
+PXELOADER_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
+START_ELTORITO_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,7C00
if NETBOOT_SUPPORT
NETBOOT_FLAGS = -I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
@@ -82,7 +82,7 @@
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
$(NETBOOT_FLAGS) $(SERIAL_FLAGS) $(HERCULES_FLAGS)
-STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
+STAGE1_5_LINK = $(STAGE2_CFLAGS) -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1
# For stage2 target.
--- grub-0.97/stage1/Makefile.am.alt-x86_64-m32 2006-07-21 11:02:14 +0400
+++ grub-0.97/stage1/Makefile.am 2006-07-21 11:09:33 +0400
@@ -5,7 +5,7 @@
# We can't use builtins or standard includes.
AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
-LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
+LDFLAGS = $(STAGE1_CFLAGS) -nostdlib -Wl,-N,-Ttext,7C00
noinst_PROGRAMS = stage1.exec
stage1_exec_SOURCES = stage1.S stage1.h
--- grub-0.97/configure.ac.alt-x86_64-m32 2005-05-08 06:36:03 +0400
+++ grub-0.97/configure.ac 2006-07-21 11:02:15 +0400
@@ -47,7 +47,9 @@
fi
if test "x$host_cpu" = xx86_64; then
- CFLAGS="-m32 $CFLAGS"
+ M32_FLAG="-m32 -nodefaultlibs"
+else
+ M32_FLAG=
fi
#
@@ -84,7 +86,7 @@
if test "x$with_binutils" != x; then
CFLAGS="-B$with_binutils/ $CFLAGS"
fi
- STAGE1_CFLAGS="-O2"
+ STAGE1_CFLAGS="$M32_FLAG -O2"
GRUB_CFLAGS="-O2"
AC_CACHE_CHECK([whether optimization for size works], size_flag, [
saved_CFLAGS=$CFLAGS
@@ -97,6 +99,7 @@
else
STAGE2_CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops"
fi
+ STAGE2_CFLAGS="$M32_FLAG $STAGE2_CFLAGS"
# OpenBSD has a GCC extension for protecting applications from
# stack smashing attacks, but GRUB doesn't want this feature.
AC_CACHE_CHECK([whether gcc has -fno-stack-protector],
@@ -157,6 +160,9 @@
AC_CHECK_TOOL(OBJCOPY, objcopy)
fi
+grub_saved_CFLAGS="$CFLAGS"
+CFLAGS="$M32_FLAG $CFLAGS"
+
# Defined in acinclude.m4.
grub_ASM_USCORE
grub_PROG_OBJCOPY_ABSOLUTE
@@ -173,6 +179,8 @@
grub_ASM_ABSOLUTE_WITHOUT_ASTERISK
+CFLAGS="$grub_saved_CFLAGS"
+
grub_CHECK_START_SYMBOL
grub_CHECK_USCORE_START_SYMBOL
if test "x$grub_cv_check_start_symbol" != "xyes" \
--- grub-0.97/stage2/disk_io.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/stage2/disk_io.c 2006-07-21 10:58:25 +0400
@@ -130,7 +130,7 @@
static inline unsigned long
grub_log2 (unsigned long word)
{
- asm volatile ("bsfl %1,%0"
+ asm volatile ("bsf %1,%0"
: "=r" (word)
: "r" (word));
return word;
--- grub-0.97/stage2/fsys_ext2fs.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/stage2/fsys_ext2fs.c 2006-07-21 10:58:25 +0400
@@ -242,7 +242,7 @@
static __inline__ unsigned long
ffz (unsigned long word)
{
- __asm__ ("bsfl %1,%0"
+ __asm__ ("bsf %1,%0"
: "=r" (word)
: "r" (~word));
return word;
--- grub-0.97/stage2/fsys_fat.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/stage2/fsys_fat.c 2006-07-21 10:58:25 +0400
@@ -57,7 +57,7 @@
static __inline__ unsigned long
grub_log2 (unsigned long word)
{
- __asm__ ("bsfl %1,%0"
+ __asm__ ("bsf %1,%0"
: "=r" (word)
: "r" (word));
return word;
--- grub-0.97/stage2/fsys_iso9660.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/stage2/fsys_iso9660.c 2006-07-21 10:58:25 +0400
@@ -59,7 +59,7 @@
static inline unsigned long
grub_log2 (unsigned long word)
{
- asm volatile ("bsfl %1,%0"
+ asm volatile ("bsf %1,%0"
: "=r" (word)
: "r" (word));
return word;
--- grub-0.97/stage2/fsys_reiserfs.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/stage2/fsys_reiserfs.c 2006-07-21 10:58:25 +0400
@@ -369,7 +369,7 @@
static __inline__ unsigned long
grub_log2 (unsigned long word)
{
- __asm__ ("bsfl %1,%0"
+ __asm__ ("bsf %1,%0"
: "=r" (word)
: "r" (word));
return word;
--- grub-0.97/stage2/fsys_xfs.c.alt-x86_64-build 2005-05-08 06:15:55 +0400
+++ grub-0.97/stage2/fsys_xfs.c 2006-07-21 10:58:25 +0400
@@ -100,26 +100,16 @@
static inline __const__ xfs_uint16_t
le16 (xfs_uint16_t x)
{
- __asm__("xchgb %b0,%h0" \
- : "=q" (x) \
- : "0" (x)); \
- return x;
+ return ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8 );
}
static inline __const__ xfs_uint32_t
le32 (xfs_uint32_t x)
{
-#if 0
- /* 386 doesn't have bswap. */
- __asm__("bswap %0" : "=r" (x) : "0" (x));
-#else
- /* This is slower but this works on all x86 architectures. */
- __asm__("xchgb %b0, %h0" \
- "\n\troll $16, %0" \
- "\n\txchgb %b0, %h0" \
- : "=q" (x) : "0" (x));
-#endif
- return x;
+ return (((x & 0x000000ffUL) << 24) |
+ ((x & 0x0000ff00UL) << 8) |
+ ((x & 0x00ff0000UL) >> 8) |
+ ((x & 0xff000000UL) >> 24));
}
static inline __const__ xfs_uint64_t
--- grub-0.97/stage2/smp-imps.c.alt-x86_64-build 2005-02-02 23:36:00 +0300
+++ grub-0.97/stage2/smp-imps.c 2006-07-21 11:01:30 +0400
@@ -270,7 +270,7 @@
/*
* This contains the local APIC hardware address.
*/
-static unsigned imps_lapic_addr = ((unsigned) (&lapic_dummy)) - LAPIC_ID;
+static unsigned long imps_lapic_addr = ((unsigned long) (&lapic_dummy)) - LAPIC_ID;
/*
* These map from virtual cpu numbers to APIC id's and back.
*/
--- grub-0.97/grub/asmstub.c.alt-x86_64-build 2006-07-21 10:58:25 +0400
+++ grub-0.97/grub/asmstub.c 2006-07-21 10:58:25 +0400
@@ -105,6 +105,12 @@
static unsigned int serial_speed;
#endif /* SIMULATE_SLOWNESS_OF_SERIAL */
+#ifdef __x86_64__
+#define SP_REG "rsp"
+#else
+#define SP_REG "esp"
+#endif
+
/* The main entry point into this mess. */
int
grub_stage2 (void)
@@ -122,7 +128,7 @@
void doit (void)
{
/* Make sure our stack lives in the simulated memory area. */
- asm volatile ("movl %%esp, %0\n\tmovl %1, %%esp\n"
+ asm volatile ("mov %%" SP_REG ", %0\n\tmov %1, %%" SP_REG "\n"
: "=&r" (realstack) : "r" (simstack));
/* Do a setjmp here for the stop command. */
@@ -140,7 +146,7 @@
}
/* Replace our stack before we use any local variables. */
- asm volatile ("movl %0, %%esp\n" : : "r" (realstack));
+ asm volatile ("mov %0, %%" SP_REG "\n" : : "r" (realstack));
}
assert (grub_scratch_mem == 0);
--- grub-0.97-alt2/grub.spec 2006-05-31 11:51:47 +0000
+++ grub-0.97-alt2.0.1/grub.spec 2006-07-21 06:58:22 +0000
@@ -1,11 +1,11 @@
Name: grub
Version: 0.97
-Release: alt2
+Release: alt2.0.1
Summary: GRand Unified Bootloader
License: GPL
Group: System/Kernel and hardware
-Exclusivearch: %ix86
+Exclusivearch: %ix86 x86_64
Source: ftp://alpha.gnu.org/gnu/grub/%name-%version.tar
#"grubonce" is script to demonstrate & ease "savedefault --once"
@@ -46,12 +46,15 @@ Patch223: stage2-wildcard-doc.dif
Patch224: grub-%{version}-protexec.patch
Patch299: grub-0.97-stackptr.diff
+Patch1000: grub-0.97-alt-x86_64-m32.patch
+Patch1001: grub-0.97-alt-x86_64-build.patch
Provides: %name-doc = %version, %name-graph = %version
Obsoletes: %name-doc, %name-graph
# Automatically added by buildreq on Wed May 31 2006
-BuildRequires: libncurses-devel reiser4progs-minimal-devel tetex-latex
+BuildRequires: libncurses-devel tetex-latex
+# reiser4progs-minimal-devel
%package utils
Group: System/Kernel and hardware
@@ -81,8 +84,8 @@ Additional utilites for %name
#%patch5 -p1
%patch6 -p1
%patch7 -p1
-%patch8 -p1
-%patch9 -p1
+#%patch8 -p1
+#%patch9 -p1
#SuSE:
rm -f acconfig.h || true
@@ -90,7 +93,7 @@ rm -f acconfig.h || true
%patch201
%patch202 -p1
%patch203 -p1
-%patch204 -p1
+###%patch204 -p1
%patch205 -p1
%patch206 -p1
%patch207 -p1
@@ -99,15 +102,18 @@ rm -f acconfig.h || true
%patch210 -p1
%patch211 -p1
%patch212 -p1
-%patch213
-%patch214
+###%patch213
+###%patch214
# Disable the wildcard feature
#%patch220 -p1
#%patch221 -p1
#%patch222 -p1
#%patch223 -p1
%patch224 -p1
-%patch299
+###%patch299
+
+%patch1000 -p1 -b .alt-x86_64-m32
+%patch1001 -p1 -b .alt-x86_64-build
%build
#rm -rf configure
@@ -117,12 +123,15 @@ rm -f acconfig.h || true
aclocal && autoheader && autoconf && automake --add-missing
###
-#%ifarch x86_64
-# EXTRACFLAGS=' -fno-strict-aliasing -minline-all-stringops -m32 -fno-asynchronous-unwind-tables '
-#%else
+%ifarch x86_64
+ EXTRACFLAGS=' -fno-strict-aliasing -minline-all-stringops -fno-asynchronous-unwind-tables '
+ STAGEx_CFLAGS=' -m32 '
+%else
EXTRACFLAGS=' -fno-strict-aliasing -minline-all-stringops'
-#%endif
-CFLAGS="$RPM_OPT_FLAGS -Os -DNDEBUG -W -Wall -Wpointer-arith $EXTRACFLAGS" ./configure \
+ STAGEx_CFLAGS=
+%endif
+CFLAGS="$RPM_OPT_FLAGS -Os -DNDEBUG -W -Wall -Wpointer-arith $EXTRACFLAGS" \
+STAGE1_CFLAGS="$STAGEx_CFLAGS" STAGE2_CFLAGS="$STAGEx_CFLAGS" ./configure \
--prefix=/usr --infodir=%{_infodir} --mandir=%{_mandir} --datadir=%{_datadir} \
--libexecdir=%{_libexecdir} \
--disable-auto-linux-mem-opt --enable-diskless \
Так оно делает вид, что собирается, но на самом деле не работает.
> > Проблема в невозможности собрать /usr/sbin/grub (кстати, а
> > почему он лежит в /usr?), в результате grub нечем установить на
> > диск при запущенной системе.
>
> Кто бы мне объяснил, зачем нужен -m32 в /usr/sbin/grub?
char *stage2_first_buffer = ...
int i;
...
i = (int) stage2_first_buffer + SECTOR_SIZE - 4;
while (*((unsigned long *) i))
{
if (i < (int) stage2_first_buffer
|| (*((int *) (i - 4)) & 0x80000000)
|| *((unsigned short *) i) >= 0xA00
|| *((short *) (i + 2)) == 0)
{
errnum = ERR_BAD_VERSION;
goto fail;
}
*((int *) i) = 0;
*((int *) (i - 4)) = 0;
i -= 8;
}
И такого кода там куча.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2006-12-21 16:13 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-20 5:04 ` Ildar Mulyukov
2006-12-20 6:51 ` Hihin Ruslan
2006-12-20 8:09 ` Anton Farygin
2006-12-20 8:34 ` Andrii Dobrovol`s`kii
2006-12-20 20:59 ` Michael Shigorin
2006-12-20 22:04 ` Pavlov Konstantin
2006-12-21 8:32 ` [devel] GRUB и LILO Michael Shigorin
2006-12-21 8:40 ` Anton Gorlov
2006-12-21 8:35 ` [devel] GRUB и сородичи Alexey I. Froloff
2006-12-21 9:34 ` Epiphanov Sergei
2006-12-21 10:13 ` Anton Farygin
2006-12-21 11:30 ` Dmitry V. Levin
2006-12-21 12:10 ` Sergey Vlasov
2006-12-21 12:22 ` Dmitry V. Levin
2006-12-21 12:50 ` Anton Farygin
2006-12-21 12:54 ` Dmitry V. Levin
2006-12-21 14:12 ` Epiphanov Sergei
2006-12-21 14:19 ` Led
2006-12-21 14:39 ` Dmitry V. Levin
2006-12-21 15:15 ` Epiphanov Sergei
2006-12-21 15:34 ` [devel] [jt] " Dmitry V. Levin
2006-12-21 15:42 ` [devel] " Sergey Vlasov
2006-12-21 15:46 ` Dmitry V. Levin
2006-12-21 16:13 ` Sergey Vlasov [this message]
2006-12-21 16:19 ` Sergey Vlasov
2006-12-22 8:26 ` Epiphanov Sergei
2006-12-21 15:20 ` Sergey Vlasov
2007-04-05 6:23 ` Hihin Ruslan
2007-04-05 6:27 ` Hihin Ruslan
2007-04-05 6:56 ` Anton Farygin
2007-04-08 3:53 ` Hihin Ruslan
2007-04-08 7:12 ` Anton Farygin
2007-04-08 10:26 ` Dmitry V. Levin
2007-04-08 10:31 ` Eugene Ostapets
2007-04-10 14:32 ` [devel] xmms2 (was: Re: GRUB и сородичи ) Igor Zubkov
2007-04-10 14:36 ` Eugene Ostapets
2007-04-08 20:40 ` [devel] GRUB и сородичи Hihin Ruslan
2007-04-08 11:22 ` Hihin Ruslan
2007-05-11 7:06 ` Hihin Ruslan
2006-12-20 11:56 ` Михаил Якушин
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061221161315.GH13343@master.mivlgu.local \
--to=vsu@altlinux.ru \
--cc=devel@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git