diff --git a/ChangeLog b/ChangeLog index b12759842..8c9d4b8be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2000-08-15 OKUJI Yoshinori + + The image `nbgrub' now relocates itself from 0x10000 to 0x8000, + since the Network Boot Image Proposal doesn't permit a second + loader to be loaded below 0x10000. Reported by Matthias + Kretschmer . + + * Makefile.am (NBLOADER_LINK): New variable. + (nbloader_exec_LDFLAGS): Set to $(NBLOADER_LINK) instead of + $(START_LINK). + * stage2/nbi.h (NBI_DEST_ADDR): Changed to 0x10000. + (NBI_DEST_SEG): New macro. + (NBI_DEST_OFF): Likewise. + (RELOCATED_ADDR): Likewise. + (RELOCATED_SEG): Likewise. + (RELOCATED_OFF): Likewise. + (STAGE2_START_ADDR): Likewise. + * stage2/nbloader.S: Added .code16 directive at the start of the + code. + Set the segment and the offset of the load address to + NBI_DEST_SEG and NBI_DEST_OFF, respectively. + Set the segment and the offset of the start address to + NBI_DEST_SEG and NBI_DEST_OFF + relocate - _start, respectively. + Added a routine for relocating itself. + (relocate): New label. + (copy_rest): Likewise. + (copy_loop): Likewise. + (copy): Likewise. + (boot_stage2): Likewise. + 2000-08-13 OKUJI Yoshinori * grub/main.c (main): Move the version number inside the diff --git a/NEWS b/NEWS index fc8c4c331..9476fb2c3 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ New in 0.5.96 - XXXX-XX-XX: unmount the partition where GRUB images reside. We'd recommend _not_ using those commands directly, but using the utility "grub-install" instead, because this is safer. +* One violation against the Network Boot Image Proposal was found and + fixed. So now the image `nbgrub' can work fine even with a card such + as rtl8139. New in 0.5.95 - 2000-06-27: * NetBSD ELF kernel support is added. You have to specify the new option diff --git a/THANKS b/THANKS index 7e06b2c10..0ea37a8e9 100644 --- a/THANKS +++ b/THANKS @@ -32,6 +32,7 @@ Klaus Reichl Kunihiro Ishiguro M. Meiarashi Mark Lundeberg +Matthias Kretschmer Michael Hohmuth Miles Bader Neal H Walfield diff --git a/stage2/Makefile.am b/stage2/Makefile.am index 25f64732f..85dd6d3f7 100644 --- a/stage2/Makefile.am +++ b/stage2/Makefile.am @@ -46,6 +46,7 @@ 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 if NETBOOT_SUPPORT STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \ @@ -147,7 +148,7 @@ diskless_size.h: diskless # For nbloader target. nbloader_exec_SOURCES = nbloader.S nbloader_exec_CFLAGS = $(STAGE2_COMPILE) -nbloader_exec_LDFLAGS = $(START_LINK) +nbloader_exec_LDFLAGS = $(NBLOADER_LINK) # XXX: See the comment for start_exec-start.o. nbloader_exec-nbloader.o: diskless_size.h diff --git a/stage2/Makefile.in b/stage2/Makefile.in index 4bbcf4da5..01a344bc2 100644 --- a/stage2/Makefile.in +++ b/stage2/Makefile.in @@ -133,6 +133,7 @@ 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 @NETBOOT_SUPPORT_TRUE@STAGE2_COMPILE = @NETBOOT_SUPPORT_TRUE@$(STAGE2_CFLAGS) -fno-builtin -nostdinc \ @NETBOOT_SUPPORT_TRUE@ -I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1 @@ -217,7 +218,7 @@ diskless_exec_LDADD = ../netboot/libdrivers.a # For nbloader target. nbloader_exec_SOURCES = nbloader.S nbloader_exec_CFLAGS = $(STAGE2_COMPILE) -nbloader_exec_LDFLAGS = $(START_LINK) +nbloader_exec_LDFLAGS = $(NBLOADER_LINK) # For pxeloader target. pxeloader_exec_SOURCES = pxeloader.S diff --git a/stage2/asm.S b/stage2/asm.S index f418fe2a5..76a9111ce 100644 --- a/stage2/asm.S +++ b/stage2/asm.S @@ -144,7 +144,7 @@ codestart: /* zero %al */ xorb %al, %al - + /* set the direction */ cld diff --git a/stage2/nbi.h b/stage2/nbi.h index eabe907bb..3f70e21ca 100644 --- a/stage2/nbi.h +++ b/stage2/nbi.h @@ -21,7 +21,13 @@ #ifndef GRUB_NBI_HEADER #define GRUB_NBI_HEADER -#define NBI_MAGIC 0x1B031336 -#define NBI_DEST_ADDR 0x8000 +#define NBI_MAGIC 0x1B031336 +#define NBI_DEST_ADDR 0x10000 +#define NBI_DEST_SEG 0x1000 +#define NBI_DEST_OFF 0x0000 +#define RELOCATED_ADDR 0x8000 +#define RELOCATED_SEG 0x0800 +#define RELOCATED_OFF 0x0000 +#define STAGE2_START_ADDR 0x8200 #endif /* ! GRUB_NBI_HEADER */ diff --git a/stage2/nbloader.S b/stage2/nbloader.S index 9f3b74a94..57ad93655 100644 --- a/stage2/nbloader.S +++ b/stage2/nbloader.S @@ -22,7 +22,8 @@ .file "nbloader.S" .text - + .code16 + /* Just a dummy entry */ .globl _start; _start: @@ -33,17 +34,88 @@ .long NBI_MAGIC .long 0x00000004 /* load address of the first block */ - .word NBI_DEST_ADDR - .word 0x0000 - /* start addr of the code (stage 2) */ - .word NBI_DEST_ADDR + 0x0200 - .word 0x0000 + .word NBI_DEST_OFF + .word NBI_DEST_SEG + /* start addr of the relocation code */ + .word NBI_DEST_OFF + (relocate - _start) + .word NBI_DEST_SEG .long 0x04000004 .long NBI_DEST_ADDR + 0x0200 .long DISKLESS_SIZE .long DISKLESS_SIZE +relocate: + /* + * This code is for now located at 0x10000. + * Relocate the code in two steps: + * 1. Copy the first 32k to 0x8000 and jump to the relocated area. + * 2. Copy the rest to 0x10000 (0x8000 + 32k). + */ + + /* Copy the first 32k */ + movw $NBI_DEST_SEG, %ax + movw %ax, %ds + movw $RELOCATED_SEG, %ax + movw %ax, %es + xorw %si, %si + xorw %di, %di + /* Always copy 32k bytes */ + movw $0x4000, %cx + + cld + rep + movsw + + /* Jump to the relocated address */ + ljmp $0, $(RELOCATED_ADDR + copy_rest - _start) + + /* Copy the rest */ +copy_rest: + /* Set %edx to the number of bytes */ + movl $(DISKLESS_SIZE + 0x200 - 0x8000), %edx + +copy_loop: + /* Check the rest */ + orl %edx, %edx + jz boot_stage2 + + /* Copy by 32k, as that is easy to implement */ + movl $0x8000, %ecx + cmpl %ecx, %edx + jg copy + movl %edx, %ecx + +copy: + /* Update the number of rest bytes */ + subl %ecx, %edx + + /* Add 0x0800 (32k >> 4) into %es and %ds */ + movw %es, %ax + addw $0x0800, %ax + movw %ax, %es + movw %ds, %ax + addw $0x800, %ax + movw %ax, %ds + + /* Zero the offsets */ + xorw %si, %si + xorw %di, %di + + /* Use word-size copy */ + addw $1, %cx + shrw $1, %cx + + /* The direction is already correct */ + rep + movsw + + jmp copy_loop + + /* Jump to the stage2 */ +boot_stage2: + ljmp $0, $STAGE2_START_ADDR + /* This ensures that the length of this image will be 1 sector */ . = _start + 0x200 - 1 .byte 0