2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>

Absolute addressing through constant with Apple's cc

	* kern/i386/pc/startup.S: Define necessary constants
	and address through it when using ABS with Apple's CC
	* boot/i386/pc/diskboot.S: likewise
	* boot/i386/pc/boot.S: likewise
	* boot/i386/pc/lnxboot.S: likewise
	* boot/i386/pc/cdboot.S: likewise
	* mmap/i386/pc/mmap_helper.S: likewise
	* commands/i386/pc/drivemap_int13h.S: likewise
This commit is contained in:
phcoder 2009-06-04 20:01:19 +00:00
parent 2b167a7218
commit 3e32590112
8 changed files with 214 additions and 1 deletions

View file

@ -1,3 +1,16 @@
2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>
Absolute addressing through constant with Apple's cc
* kern/i386/pc/startup.S: Define necessary constants
and address through it when using ABS with Apple's CC
* boot/i386/pc/diskboot.S: likewise
* boot/i386/pc/boot.S: likewise
* boot/i386/pc/lnxboot.S: likewise
* boot/i386/pc/cdboot.S: likewise
* mmap/i386/pc/mmap_helper.S: likewise
* commands/i386/pc/drivemap_int13h.S: likewise
2009-06-04 Vladimir Serbinenko <phcoder@gmail.com> 2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>
Check if compiler is apple cc Check if compiler is apple cc

View file

@ -30,7 +30,11 @@
#define ABS(x) (x-_start+0x7c00) #define ABS(x) (x-_start+0x7c00)
/* Print message string */ /* Print message string */
#ifdef APPLE_CC
#define MSG(x) x ## _abs = ABS(x); movw $x ## _abs, %si; call message
#else
#define MSG(x) movw $ABS(x), %si; call message #define MSG(x) movw $ABS(x), %si; call message
#endif
.file "boot.S" .file "boot.S"
@ -125,7 +129,12 @@ boot_drive_check:
* ljmp to the next instruction because some bogus BIOSes * ljmp to the next instruction because some bogus BIOSes
* jump to 07C0:0000 instead of 0000:7C00. * jump to 07C0:0000 instead of 0000:7C00.
*/ */
#ifdef APPLE_CC
real_start_abs = ABS(real_start)
ljmp $0, $(real_start_abs)
#else
ljmp $0, $ABS(real_start) ljmp $0, $ABS(real_start)
#endif
real_start: real_start:
@ -143,7 +152,12 @@ real_start:
* Check if we have a forced disk reference here * Check if we have a forced disk reference here
*/ */
/* assign root_drive at the same time */ /* assign root_drive at the same time */
movw ABS(boot_drive), %ax #ifdef APPLE_CC
boot_drive_abs = ABS (boot_drive)
movw boot_drive_abs, %ax
#else
movw ABS(boot_drive), %ax
#endif
movb %ah, %dh movb %ah, %dh
cmpb $0xff, %al cmpb $0xff, %al
je 1f je 1f
@ -156,7 +170,12 @@ real_start:
MSG(notification_string) MSG(notification_string)
/* set %si to the disk address packet */ /* set %si to the disk address packet */
#ifdef APPLE_CC
disk_address_packet_abs = ABS (disk_address_packet)
movw $disk_address_packet_abs, %si
#else
movw $ABS(disk_address_packet), %si movw $ABS(disk_address_packet), %si
#endif
/* do not probe LBA if the drive is a floppy */ /* do not probe LBA if the drive is a floppy */
testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
@ -197,10 +216,18 @@ lba_mode:
movw $0x0010, (%si) movw $0x0010, (%si)
/* the absolute address */ /* the absolute address */
#ifdef APPLE_CC
kernel_sector_abs = ABS (kernel_sector)
movl (kernel_sector_abs), %ebx
movl %ebx, 8(%si)
movl (kernel_sector_abs + 4), %ebx
movl %ebx, 12(%si)
#else
movl ABS(kernel_sector), %ebx movl ABS(kernel_sector), %ebx
movl %ebx, 8(%si) movl %ebx, 8(%si)
movl ABS(kernel_sector + 4), %ebx movl ABS(kernel_sector + 4), %ebx
movl %ebx, 12(%si) movl %ebx, 12(%si)
#endif
/* the segment of buffer address */ /* the segment of buffer address */
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si) movw $GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si)
@ -267,12 +294,22 @@ final_init:
setup_sectors: setup_sectors:
/* load logical sector start (top half) */ /* load logical sector start (top half) */
#ifdef APPLE_CC
kernel_sector_abs = ABS (kernel_sector)
movl (kernel_sector_abs + 4), %eax
#else
movl ABS(kernel_sector + 4), %eax movl ABS(kernel_sector + 4), %eax
#endif
orl %eax, %eax orl %eax, %eax
jnz geometry_error jnz geometry_error
/* load logical sector start (bottom half) */ /* load logical sector start (bottom half) */
#ifdef APPLE_CC
movl (kernel_sector_abs), %eax
#else
movl ABS(kernel_sector), %eax movl ABS(kernel_sector), %eax
#endif
/* zero %edx */ /* zero %edx */
xorl %edx, %edx xorl %edx, %edx
@ -336,7 +373,12 @@ setup_sectors:
movw %es, %bx movw %es, %bx
copy_buffer: copy_buffer:
#ifdef APPLE_CC
kernel_segment_abs = ABS (kernel_segment)
movw (kernel_segment_abs), %es
#else
movw ABS(kernel_segment), %es movw ABS(kernel_segment), %es
#endif
/* /*
* We need to save %cx and %si because the startup code in * We need to save %cx and %si because the startup code in
@ -360,7 +402,12 @@ copy_buffer:
popw %dx popw %dx
/* boot kernel */ /* boot kernel */
#ifdef APPLE_CC
kernel_address_abs = ABS (kernel_address)
jmp *(kernel_address_abs)
#else
jmp *(kernel_address) jmp *(kernel_address)
#endif
/* END OF MAIN LOOP */ /* END OF MAIN LOOP */
@ -446,7 +493,12 @@ floppy_probe:
* Perform floppy probe. * Perform floppy probe.
*/ */
#ifdef APPLE_CC
probe_values_abs = ABS (probe_values)
movw $(probe_values_abs-1), %si
#else
movw $ABS(probe_values-1), %si movw $ABS(probe_values-1), %si
#endif
probe_loop: probe_loop:
/* reset floppy controller INT 13h AH=0 */ /* reset floppy controller INT 13h AH=0 */

View file

@ -67,8 +67,15 @@ bi_reserved:
movw %ax, %ds movw %ax, %ds
movw %ax, %es 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 movw $(0x7C00 + err_noboot_msg - start), %si
movl %cs: bi_length - next(%bx), %ecx movl %cs: bi_length - next(%bx), %ecx
#endif
orl %ecx, %ecx orl %ecx, %ecx
jz fail jz fail
@ -152,7 +159,12 @@ read_cdrom:
ret ret
cdrom_fail: cdrom_fail:
#ifdef APPLE_CC
err_cdfail_msg_abs = 0x7C00 + err_cdfail_msg - start
movw $(err_cdfail_msg_abs), %si
#else
movw $(0x7C00 + err_cdfail_msg - start), %si movw $(0x7C00 + err_cdfail_msg - start), %si
#endif
fail: fail:
movb $0x0e, %ah movb $0x0e, %ah

View file

@ -28,7 +28,11 @@
#define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR) #define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR)
/* Print message string */ /* 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 #define MSG(x) movw $ABS(x), %si; call message
#endif
.file "diskboot.S" .file "diskboot.S"
@ -61,7 +65,12 @@ _start:
popw %si popw %si
/* this sets up for the first run through "bootloop" */ /* 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 movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di
#endif
/* save the sector number of the second sector in %ebp */ /* save the sector number of the second sector in %ebp */
movl (%di), %ebp movl (%di), %ebp

View file

@ -123,8 +123,15 @@ data_leng:
linux_init: 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
movw %cs:(reg_edx - start), %dx movw %cs:(reg_edx - start), %dx
movl %cs:(code32_start - start), %ebp movl %cs:(code32_start - start), %ebp
#endif
linux_next: linux_next:
@ -132,12 +139,22 @@ linux_next:
normalize: normalize:
popw %bx popw %bx
#ifdef APPLE_CC
normalize_rel = normalize - start
subw $(normalize_rel), %bx
#else
subw $(normalize - start), %bx subw $(normalize - start), %bx
#endif
shrw $4, %bx shrw $4, %bx
movw %cs, %ax movw %cs, %ax
addw %bx, %ax addw %bx, %ax
pushw %ax pushw %ax
#ifdef APPLE_CC
real_code_rel = real_code - start
pushw $(real_code_rel)
#else
pushw $(real_code - start) pushw $(real_code - start)
#endif
lret /* Jump to real_code. */ lret /* Jump to real_code. */
real_code: real_code:
@ -164,7 +181,12 @@ real_code:
rep rep
movsl 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) ljmp $(CODE_ADDR >> 4), $(real_code_2 - start)
#endif
real_code_2: real_code_2:
@ -189,8 +211,15 @@ real_code_2:
cmpl $MULTIBOOT_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END) cmpl $MULTIBOOT_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END)
jz 1f 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_image - start), %esi
movl (ramdisk_size - start), %ecx movl (ramdisk_size - start), %ecx
#endif
movl $(DATA_ADDR - 0x200), %edi movl $(DATA_ADDR - 0x200), %edi
jmp 2f jmp 2f
@ -205,7 +234,12 @@ real_code_2:
movsbl %dh, %eax movsbl %dh, %eax
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) 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 movsbl (reg_edx + 2 - start), %eax
#endif
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART) movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
movb $0xFF, %dh movb $0xFF, %dh
@ -234,6 +268,28 @@ move_memory:
pushl %ecx pushl %ecx
movl %esi, %eax 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) movw %si, (gdt_src1 - start)
shrl $16, %eax shrl $16, %eax
movb %al, (gdt_src1 + 2 - start) movb %al, (gdt_src1 + 2 - start)
@ -248,6 +304,7 @@ move_memory:
movw $(gdt - start), %si movw $(gdt - start), %si
movb $0x87, %ah movb $0x87, %ah
shrw $1, %cx shrw $1, %cx
#endif
int $0x15 int $0x15
@ -257,7 +314,12 @@ move_memory:
popl %esi popl %esi
jnc 2f 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 movw $(err_int15_msg - start), %si
#endif
jmp fail jmp fail
2: 2:

View file

@ -30,7 +30,12 @@ FUNCTION(grub_drivemap_handler)
/* Map the drive number (always in DL). */ /* Map the drive number (always in DL). */
push %ax push %ax
push %bx push %bx
#ifdef APPLE_CC
grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart))
movw $grub_drivemap_mapstart_ofs, %bx
#else
movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx
#endif
more_remaining: more_remaining:
movw %cs:(%bx), %ax movw %cs:(%bx), %ax

View file

@ -69,7 +69,12 @@ _start:
/* /*
* Guarantee that "main" is loaded at 0x0:0x8200. * Guarantee that "main" is loaded at 0x0:0x8200.
*/ */
#ifdef APPLE_CC
codestart_abs = ABS(codestart) - 0x10000
ljmp $0, $(codestart_abs)
#else
ljmp $0, $ABS(codestart) ljmp $0, $ABS(codestart)
#endif
/* /*
* Compatibility version number * Compatibility version number
@ -249,12 +254,24 @@ codestart:
movsb movsb
#endif #endif
#ifdef APPLE_CC
/* clean out the bss */
bss_start_abs = ABS (bss_start)
bss_end_abs = ABS (bss_end)
movl bss_start_abs, %edi
/* compute the bss length */
movl bss_end_abs, %ecx
subl %edi, %ecx
#else
/* clean out the bss */ /* clean out the bss */
movl $BSS_START_SYMBOL, %edi movl $BSS_START_SYMBOL, %edi
/* compute the bss length */ /* compute the bss length */
movl $END_SYMBOL, %ecx movl $END_SYMBOL, %ecx
subl %edi, %ecx subl %edi, %ecx
#endif
/* clean out */ /* clean out */
xorl %eax, %eax xorl %eax, %eax
@ -293,7 +310,13 @@ real_to_prot:
cli cli
/* load the GDT register */ /* load the GDT register */
#ifdef APPLE_CC
mov %cs, %ax
mov %ax, %ds
DATA32 ADDR32 lgdt gdtdesc
#else
DATA32 ADDR32 lgdt %cs:gdtdesc DATA32 ADDR32 lgdt %cs:gdtdesc
#endif
/* turn on protected mode */ /* turn on protected mode */
movl %cr0, %eax movl %cr0, %eax
@ -1223,7 +1246,12 @@ translate_keycode:
pushw %bx pushw %bx
pushw %si pushw %si
#ifdef APPLE_CC
translation_table_abs = ABS (translation_table) - 0x10000
movw $(translation_table_abs), %si
#else
movw $ABS(translation_table), %si movw $ABS(translation_table), %si
#endif
1: lodsw 1: lodsw
/* check if this is the end */ /* check if this is the end */

View file

@ -28,7 +28,12 @@ VARIABLE(grub_machine_mmaphook_int12)
push %ds push %ds
push %cs push %cs
pop %ds pop %ds
#ifdef APPLE_CC
grub_machine_mmaphook_kblow_rel = DS (EXT_C (grub_machine_mmaphook_kblow))
movw (grub_machine_mmaphook_kblow_rel), %ax
#else
movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax
#endif
pop %ds pop %ds
iret iret
@ -53,8 +58,15 @@ e801:
push %ds push %ds
push %cs push %cs
pop %ds pop %ds
#ifdef APPLE_CC
grub_machine_mmaphook_kbin16mb_rel = DS (EXT_C (grub_machine_mmaphook_kbin16mb))
grub_machine_mmaphook_64kbin4gb_rel = DS (EXT_C (grub_machine_mmaphook_64kbin4gb))
movw (grub_machine_mmaphook_kbin16mb_rel), %ax
movw (grub_machine_mmaphook_64kbin4gb_rel), %bx
#else
movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax
movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx
#endif
movw %ax, %cx movw %ax, %cx
movw %bx, %dx movw %bx, %dx
pop %ds pop %ds
@ -66,26 +78,42 @@ h88:
push %ds push %ds
push %cs push %cs
pop %ds pop %ds
#ifdef APPLE_CC
movw (grub_machine_mmaphook_kbin16mb_rel), %ax
#else
movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax
#endif
pop %ds pop %ds
clc clc
iret iret
e820: e820:
#ifdef APPLE_CC
mmaphook_mmap_rel = DS(mmaphook_mmap)
mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num))
#endif
popf popf
push %ds push %ds
push %cs push %cs
pop %ds pop %ds
cmpw $20, %cx cmpw $20, %cx
jb errexit jb errexit
#ifdef APPLE_CC
cmpw (mmaphook_mmap_num_rel), %bx
#else
cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx
#endif
jae errexit jae errexit
cmp $0x534d4150, %edx cmp $0x534d4150, %edx
jne errexit jne errexit
push %si push %si
push %di push %di
movw $20, %cx movw $20, %cx
#ifdef APPLE_CC
movl $(mmaphook_mmap_rel), %esi
#else
movw $(DS(mmaphook_mmap)), %si movw $(DS(mmaphook_mmap)), %si
#endif
mov %bx, %ax mov %bx, %ax
imul $20, %ax imul $20, %ax
add %ax, %si add %ax, %si
@ -94,7 +122,11 @@ e820:
pop %si pop %si
movl $20, %ecx movl $20, %ecx
inc %bx inc %bx
#ifdef APPLE_CC
cmpw (mmaphook_mmap_num_rel), %bx
#else
cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx
#endif
jb noclean jb noclean
xor %bx, %bx xor %bx, %bx
noclean: noclean: