2009-08-14 Pavel Roskin <proski@gnu.org>

* boot/i386/pc/cdboot.S: Use LOCAL for local labels.  Eliminate
	ABS and APPLE_CC.
	* boot/i386/pc/diskboot.S: Likewise.
	* boot/i386/pc/lnxboot.S: Likewise.  Hardcode the number of code
	sectors allow compilation on MacOSX.
	* conf/i386-pc.rmk: Enable unconditional compilation of
	lnxboot.img.
This commit is contained in:
proski 2009-08-14 04:12:22 +00:00
parent 9a10df160e
commit d404ee5646
5 changed files with 63 additions and 164 deletions

View file

@ -1,3 +1,13 @@
2009-08-14 Pavel Roskin <proski@gnu.org>
* boot/i386/pc/cdboot.S: Use LOCAL for local labels. Eliminate
ABS and APPLE_CC.
* boot/i386/pc/diskboot.S: Likewise.
* boot/i386/pc/lnxboot.S: Likewise. Hardcode the number of code
sectors allow compilation on MacOSX.
* conf/i386-pc.rmk: Enable unconditional compilation of
lnxboot.img.
2009-08-13 Colin Watson <cjwatson@ubuntu.com>
* util/grub-mkconfig.in: Export GRUB_HIDDEN_TIMEOUT.

View file

@ -17,6 +17,7 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <grub/boot.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
@ -38,9 +39,9 @@
start:
_start:
call next
call LOCAL(next)
next:
LOCAL(next):
jmp 1f
. = start + 8
@ -67,24 +68,17 @@ bi_reserved:
movw %ax, %ds
movw %ax, %es
#ifdef APPLE_CC
err_noboot_msg_abs = 0x7C00 + err_noboot_msg - start
movw $err_noboot_msg_abs, %si
bi_length_dif = bi_length - next
movl %cs:bi_length_dif(%bx), %ecx
#else
movw $(0x7C00 + err_noboot_msg - start), %si
movl %cs: bi_length - next(%bx), %ecx
#endif
movl %cs: bi_length - LOCAL(next)(%bx), %ecx
orl %ecx, %ecx
jz fail
jz LOCAL(fail)
addl $((1 << CDSEC_SHIFT) - 1), %ecx
shrl $CDSEC_SHIFT, %ecx
movl %cs: bi_file - next(%bx), %esi
movl %cs: bi_file - LOCAL(next)(%bx), %esi
call read_cdrom
call LOCAL(read_cdrom)
ljmp $(DATA_ADDR >> 4), $0
@ -93,7 +87,7 @@ bi_reserved:
* esi: start sector
* ecx: number of sectors
*/
read_cdrom:
LOCAL(read_cdrom):
xorl %eax, %eax
/* Number of blocks to read. */
@ -134,7 +128,7 @@ read_cdrom:
2:
shrw $1, %di /* Reduce transfer size. */
jz cdrom_fail
jz LOCAL(cdrom_fail)
movw %di, 0x10(%si)
movw %di, 2(%si)
movb $0x42, %ah
@ -155,15 +149,10 @@ read_cdrom:
addw $0x12, %sp
ret
cdrom_fail:
#ifdef APPLE_CC
err_cdfail_msg_abs = 0x7C00 + err_cdfail_msg - start
movw $(err_cdfail_msg_abs), %si
#else
LOCAL(cdrom_fail):
movw $(0x7C00 + err_cdfail_msg - start), %si
#endif
fail:
LOCAL(fail):
movb $0x0e, %ah
xorw %bx, %bx
1:

View file

@ -16,23 +16,14 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <grub/machine/boot.h>
/*
* defines for the code go here
*/
/* Absolute addresses
This makes the assembler generate the address without support
from the linker. (ELF can't relocate 16-bit addresses!) */
#define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR)
/* Print message string */
#ifdef APPLE_CC
#define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message
#else
#define MSG(x) movw $ABS(x), %si; call message
#endif
#define MSG(x) movw $x, %si; call LOCAL(message)
.file "diskboot.S"
@ -65,33 +56,27 @@ _start:
popw %si
/* this sets up for the first run through "bootloop" */
#ifdef APPLE_CC
firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE)
movl $firstlist_off_abs, %edi
#else
movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di
#endif
movw $(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di
/* save the sector number of the second sector in %ebp */
movl (%di), %ebp
/* this is the loop for reading the rest of the kernel in */
bootloop:
LOCAL(bootloop):
/* check the number of sectors to read */
cmpw $0, 8(%di)
/* if zero, go to the start function */
je bootit
je LOCAL(bootit)
setup_sectors:
LOCAL(setup_sectors):
/* check if we use LBA or CHS */
cmpb $0, -1(%si)
/* jump to chs_mode if zero */
je chs_mode
/* use CHS if zero, LBA otherwise */
je LOCAL(chs_mode)
lba_mode:
/* load logical sector start */
movl (%di), %ebx
movl 4(%di), %ecx
@ -150,16 +135,16 @@ lba_mode:
movb $0x42, %ah
int $0x13
jc read_error
jc LOCAL(read_error)
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
jmp copy_buffer
jmp LOCAL(copy_buffer)
chs_mode:
LOCAL(chs_mode):
/* load logical sector start (top half) */
movl 4(%di), %eax
orl %eax, %eax
jnz geometry_error
jnz LOCAL(geometry_error)
/* load logical sector start (bottom half) */
movl (%di), %eax
@ -184,7 +169,7 @@ chs_mode:
/* do we need too many cylinders? */
cmpw 8(%si), %ax
jge geometry_error
jge LOCAL(geometry_error)
/* determine the maximum sector length of this read */
movw (%si), %ax /* get number of sectors per track/head */
@ -254,12 +239,12 @@ chs_mode:
movb $0x2, %ah /* function 2 */
int $0x13
jc read_error
jc LOCAL(read_error)
/* save source segment */
movw %es, %bx
copy_buffer:
LOCAL(copy_buffer):
/* load addresses for copy from disk buffer to destination */
movw 10(%di), %es /* load destination segment */
@ -299,17 +284,17 @@ copy_buffer:
/* check if finished with this dataset */
cmpw $0, 8(%di)
jne setup_sectors
jne LOCAL(setup_sectors)
/* update position to load from */
subw $GRUB_BOOT_MACHINE_LIST_SIZE, %di
/* jump to bootloop */
jmp bootloop
jmp LOCAL(bootloop)
/* END OF MAIN LOOP */
bootit:
LOCAL(bootit):
/* print a newline */
MSG(notification_done)
popw %dx /* this makes sure %dl is our "boot" drive */
@ -319,21 +304,21 @@ bootit:
/*
* BIOS Geometry translation error (past the end of the disk geometry!).
*/
geometry_error:
LOCAL(geometry_error):
MSG(geometry_error_string)
jmp general_error
jmp LOCAL(general_error)
/*
* Read error on the disk.
*/
read_error:
LOCAL(read_error):
MSG(read_error_string)
general_error:
LOCAL(general_error):
MSG(general_error_string)
/* go here when you need to stop the machine hard after an error condition */
stop: jmp stop
LOCAL(stop): jmp LOCAL(stop)
notification_string: .asciz "loading"
@ -361,12 +346,11 @@ general_error_string: .asciz " Error"
int $0x10 /* display a byte */
incw %si
message:
LOCAL(message):
movb (%si), %al
cmpb $0, %al
jne 1b /* if not end of string, jmp to display */
ret
lastlist:
/*
* This area is an empty space between the main body of code below which

View file

@ -18,6 +18,7 @@
*/
#include <config.h>
#include <grub/symbol.h>
#include <grub/boot.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
@ -25,14 +26,8 @@
.file "lnxboot.S"
#ifdef APPLE_CC
#error Building lnxboot.img with Apple's as results in an unusable image
#endif
#define CODE_ADDR 0x6000
#ifndef APPLE_CC
#define CODE_LENG (code_end - start)
#endif
#define CODE_SECTORS 1
#define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
#define BLCK_LENG 0x4000
@ -45,17 +40,12 @@
data_start:
xorl %ebp, %ebp
jmp linux_next
jmp LOCAL(linux_next)
. = data_start + 0x1F1
setup_sects:
/* Apple's cc can't fill this value. */
#ifdef APPLE_CC
.byte 0
#else
.byte (CODE_LENG >> 9)
#endif
.byte CODE_SECTORS
root_flags:
.word 0
syssize:
@ -74,7 +64,7 @@ boot_flag:
start:
_start:
jmp linux_init
jmp LOCAL(linux_init)
.ascii "HdrS" /* Header signature. */
.word 0x0203 /* Header version number. */
@ -132,40 +122,22 @@ reg_edx:
data_leng:
.long 0
linux_init:
#ifdef APPLE_CC
reg_edx_rel = reg_edx - start
code32_start_rel = code32_start - start
movw %cs:(reg_edx_rel), %dx
movl %cs:(code32_start_rel), %ebp
#else
LOCAL(linux_init):
movw %cs:(reg_edx - start), %dx
movl %cs:(code32_start - start), %ebp
#endif
linux_next:
LOCAL(linux_next):
call normalize
call LOCAL(normalize)
normalize:
LOCAL(normalize):
popw %bx
#ifdef APPLE_CC
normalize_rel = normalize - start
subw $(normalize_rel), %bx
#else
subw $(normalize - start), %bx
#endif
subw $(LOCAL(normalize) - start), %bx
shrw $4, %bx
movw %cs, %ax
addw %bx, %ax
pushw %ax
#ifdef APPLE_CC
real_code_rel = real_code - start
pushw $(real_code_rel)
#else
pushw $(real_code - start)
#endif
lret /* Jump to real_code. */
real_code:
@ -191,13 +163,7 @@ real_code:
rep
movsl
#ifdef APPLE_CC
real_code_2_rel = real_code_2 - start
ljmp $(CODE_ADDR >> 4), $(real_code_2_rel)
#else
ljmp $(CODE_ADDR >> 4), $(real_code_2 - start)
#endif
real_code_2:
@ -216,21 +182,14 @@ real_code_2:
addl %ecx, %esi
movl $DATA_ADDR, %edi
call move_memory
call LOCAL(move_memory)
/* Check for multiboot signature. */
cmpl $MULTIBOOT_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END)
jz 1f
#ifdef APPLE_CC
ramdisk_image_rel = ramdisk_image - start
ramdisk_size_rel = ramdisk_size - start
movl (ramdisk_image_rel), %esi
movl (ramdisk_size_rel), %ecx
#else
movl (ramdisk_image - start), %esi
movl (ramdisk_size - start), %ecx
#endif
movl $(DATA_ADDR - 0x200), %edi
jmp 2f
@ -240,17 +199,11 @@ real_code_2:
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx
2:
call move_memory
call LOCAL(move_memory)
movsbl %dh, %eax
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)
#ifdef APPLE_CC
reg_edx_rel = reg_edx - start
movsbl (reg_edx_rel + 2), %eax
#else
movsbl (reg_edx + 2 - start), %eax
#endif
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
movb $0xFF, %dh
@ -264,7 +217,7 @@ real_code_2:
* ecx: number of bytes
*/
move_memory:
LOCAL(move_memory):
incl %ecx
andb $0xFE, %cl
pushw %dx
@ -279,28 +232,6 @@ move_memory:
pushl %ecx
movl %esi, %eax
#ifdef APPLE_CC
gdt_src1_rel = gdt_src1 - start
gdt_src2_rel = gdt_src2 - start
gdt_dst1_rel = gdt_dst1 - start
gdt_dst2_rel = gdt_dst2 - start
gdt_rel = gdt - start
movw %si, (gdt_src1_rel)
shrl $16, %eax
movb %al, (gdt_src1_rel + 2)
movb %ah, (gdt_src2_rel)
movl %edi, %eax
movw %di, (gdt_dst1_rel)
shrl $16, %eax
movb %al, (gdt_dst1_rel + 2)
movb %ah, (gdt_dst2_rel)
movw $(gdt_rel), %si
movb $0x87, %ah
shrw $1, %cx
#else
movw %si, (gdt_src1 - start)
shrl $16, %eax
movb %al, (gdt_src1 + 2 - start)
@ -315,7 +246,6 @@ move_memory:
movw $(gdt - start), %si
movb $0x87, %ah
shrw $1, %cx
#endif
int $0x15
@ -325,13 +255,8 @@ move_memory:
popl %esi
jnc 2f
#ifdef APPLE_CC
err_int15_msg_rel = err_int15_msg - start
movw $(err_int15_msg_rel), %si
#else
movw $(err_int15_msg - start), %si
#endif
jmp fail
jmp LOCAL(fail)
2:
@ -349,7 +274,7 @@ move_memory:
* si: message
*/
fail:
LOCAL(fail):
movb $0x0e, %ah
xorw %bx, %bx
1:
@ -362,11 +287,4 @@ fail:
err_int15_msg:
.ascii "move memory fails\0"
/* Unsupported feature in Apple's cc. */
#ifndef APPLE_CC
. = (. & (~0x1FF)) + 0x1FF
#endif
.byte 0
code_end:
. = _start + CODE_SECTORS * 512

View file

@ -10,7 +10,8 @@ COMMON_LDFLAGS = -m32 -nostdlib
script/sh/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images.
pkglib_IMAGES = boot.img diskboot.img kernel.img pxeboot.img cdboot.img
pkglib_IMAGES = boot.img cdboot.img diskboot.img kernel.img lnxboot.img \
pxeboot.img
# For boot.img.
boot_img_SOURCES = boot/i386/pc/boot.S
@ -31,9 +32,6 @@ diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)8000
diskboot_img_FORMAT = binary
# For lnxboot.img.
ifeq ($(TARGET_APPLE_CC), 0)
pkglib_IMAGES += lnxboot.img
endif
lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S
lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS)
lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)6000