* [PATCH 6/18] define asm constant for absolute memory access
@ 2009-05-30 14:46 Vladimir 'phcoder' Serbinenko
2009-06-16 1:28 ` Pavel Roskin
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-05-30 14:46 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 121 bytes --]
To access an absolute address you need to do it through a label on Apple's cc
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: 06_abs.diff --]
[-- Type: text/x-patch, Size: 11490 bytes --]
diff --git a/boot/i386/pc/boot.S b/boot/i386/pc/boot.S
index fc31f5a..c22dccd 100644
--- a/boot/i386/pc/boot.S
+++ b/boot/i386/pc/boot.S
@@ -30,7 +30,11 @@
#define ABS(x) (x-_start+0x7c00)
/* 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
+#endif
.file "boot.S"
@@ -125,7 +129,12 @@ boot_drive_check:
* ljmp to the next instruction because some bogus BIOSes
* 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)
+#endif
real_start:
@@ -143,7 +152,12 @@ real_start:
* Check if we have a forced disk reference here
*/
/* 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
cmpb $0xff, %al
je 1f
@@ -156,7 +170,12 @@ real_start:
MSG(notification_string)
/* 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
+#endif
/* do not probe LBA if the drive is a floppy */
testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
@@ -197,10 +216,18 @@ lba_mode:
movw $0x0010, (%si)
/* 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 %ebx, 8(%si)
movl ABS(kernel_sector + 4), %ebx
movl %ebx, 12(%si)
+#endif
/* the segment of buffer address */
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si)
@@ -267,12 +294,22 @@ final_init:
setup_sectors:
/* 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
+#endif
+
orl %eax, %eax
jnz geometry_error
/* load logical sector start (bottom half) */
+#ifdef APPLE_CC
+ movl (kernel_sector_abs), %eax
+#else
movl ABS(kernel_sector), %eax
+#endif
/* zero %edx */
xorl %edx, %edx
@@ -336,7 +373,12 @@ setup_sectors:
movw %es, %bx
copy_buffer:
+#ifdef APPLE_CC
+ kernel_segment_abs = ABS (kernel_segment)
+ movw (kernel_segment_abs), %es
+#else
movw ABS(kernel_segment), %es
+#endif
/*
* We need to save %cx and %si because the startup code in
@@ -360,7 +402,12 @@ copy_buffer:
popw %dx
/* boot kernel */
+#ifdef APPLE_CC
+ kernel_address_abs = ABS (kernel_address)
+ jmp *(kernel_address_abs)
+#else
jmp *(kernel_address)
+#endif
/* END OF MAIN LOOP */
@@ -446,7 +493,12 @@ 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
+#endif
probe_loop:
/* reset floppy controller INT 13h AH=0 */
diff --git a/boot/i386/pc/cdboot.S b/boot/i386/pc/cdboot.S
index 133f8de..b32f82c 100644
--- a/boot/i386/pc/cdboot.S
+++ b/boot/i386/pc/cdboot.S
@@ -67,8 +67,15 @@ 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
orl %ecx, %ecx
jz fail
@@ -152,7 +159,12 @@ read_cdrom:
ret
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
+#endif
fail:
movb $0x0e, %ah
diff --git a/boot/i386/pc/diskboot.S b/boot/i386/pc/diskboot.S
index 0c8e75d..f29ddaa 100644
--- a/boot/i386/pc/diskboot.S
+++ b/boot/i386/pc/diskboot.S
@@ -28,7 +28,11 @@
#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
.file "diskboot.S"
@@ -61,7 +65,12 @@ _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
/* save the sector number of the second sector in %ebp */
movl (%di), %ebp
diff --git a/boot/i386/pc/lnxboot.S b/boot/i386/pc/lnxboot.S
index e7f55df..0db6826 100644
--- a/boot/i386/pc/lnxboot.S
+++ b/boot/i386/pc/lnxboot.S
@@ -123,8 +123,15 @@ data_leng:
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
movl %cs:(code32_start - start), %ebp
+#endif
linux_next:
@@ -132,12 +139,22 @@ linux_next:
normalize:
popw %bx
+#ifdef APPLE_CC
+ normalize_rel = normalize - start
+ subw $(normalize_rel), %bx
+#else
subw $(normalize - start), %bx
+#endif
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:
@@ -164,7 +181,12 @@ 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:
@@ -189,8 +211,15 @@ real_code_2:
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
@@ -205,7 +234,12 @@ real_code_2:
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
@@ -234,6 +268,28 @@ 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)
@@ -248,6 +304,7 @@ move_memory:
movw $(gdt - start), %si
movb $0x87, %ah
shrw $1, %cx
+#endif
int $0x15
@@ -257,7 +314,12 @@ 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
2:
diff --git a/commands/i386/pc/drivemap_int13h.S b/commands/i386/pc/drivemap_int13h.S
index 23b7302..7a3e8e7 100644
--- a/commands/i386/pc/drivemap_int13h.S
+++ b/commands/i386/pc/drivemap_int13h.S
@@ -30,7 +30,12 @@ FUNCTION(grub_drivemap_handler)
/* Map the drive number (always in DL). */
push %ax
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
+#endif
more_remaining:
movw %cs:(%bx), %ax
diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S
index fc83c4c..23f84ed 100644
--- a/kern/i386/pc/startup.S
+++ b/kern/i386/pc/startup.S
@@ -69,7 +69,12 @@ _start:
/*
* 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)
+#endif
/*
* Compatibility version number
@@ -249,12 +254,24 @@ codestart:
movsb
#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 */
movl $BSS_START_SYMBOL, %edi
/* compute the bss length */
movl $END_SYMBOL, %ecx
subl %edi, %ecx
+#endif
/* clean out */
xorl %eax, %eax
@@ -293,7 +310,13 @@ real_to_prot:
cli
/* load the GDT register */
+#ifdef APPLE_CC
+ mov %cs, %ax
+ mov %ax, %ds
+ DATA32 ADDR32 lgdt gdtdesc
+#else
DATA32 ADDR32 lgdt %cs:gdtdesc
+#endif
/* turn on protected mode */
movl %cr0, %eax
@@ -1223,7 +1246,12 @@ translate_keycode:
pushw %bx
pushw %si
+#ifdef APPLE_CC
+ translation_table_abs = ABS (translation_table) - 0x10000
+ movw $(translation_table_abs), %si
+#else
movw $ABS(translation_table), %si
+#endif
1: lodsw
/* check if this is the end */
diff --git a/mmap/i386/pc/mmap_helper.S b/mmap/i386/pc/mmap_helper.S
index ab7c0d2..f153f1c 100644
--- a/mmap/i386/pc/mmap_helper.S
+++ b/mmap/i386/pc/mmap_helper.S
@@ -28,7 +28,12 @@ VARIABLE(grub_machine_mmaphook_int12)
push %ds
push %cs
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
+#endif
pop %ds
iret
@@ -53,8 +58,15 @@ e801:
push %ds
push %cs
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_64kbin4gb)), %bx
+#endif
movw %ax, %cx
movw %bx, %dx
pop %ds
@@ -66,26 +78,42 @@ h88:
push %ds
push %cs
pop %ds
+#ifdef APPLE_CC
+ movw (grub_machine_mmaphook_kbin16mb_rel), %ax
+#else
movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax
+#endif
pop %ds
clc
iret
e820:
+#ifdef APPLE_CC
+ mmaphook_mmap_rel = DS(mmaphook_mmap)
+ mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num))
+#endif
popf
push %ds
push %cs
pop %ds
cmpw $20, %cx
jb errexit
+#ifdef APPLE_CC
+ cmpw (mmaphook_mmap_num_rel), %bx
+#else
cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx
+#endif
jae errexit
cmp $0x534d4150, %edx
jne errexit
push %si
push %di
movw $20, %cx
+#ifdef APPLE_CC
+ movl $(mmaphook_mmap_rel), %esi
+#else
movw $(DS(mmaphook_mmap)), %si
+#endif
mov %bx, %ax
imul $20, %ax
add %ax, %si
@@ -94,7 +122,11 @@ e820:
pop %si
movl $20, %ecx
inc %bx
+#ifdef APPLE_CC
+ cmpw (mmaphook_mmap_num_rel), %bx
+#else
cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx
+#endif
jb noclean
xor %bx, %bx
noclean:
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 6/18] define asm constant for absolute memory access
2009-05-30 14:46 [PATCH 6/18] define asm constant for absolute memory access Vladimir 'phcoder' Serbinenko
@ 2009-06-16 1:28 ` Pavel Roskin
2009-06-16 10:49 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Roskin @ 2009-06-16 1:28 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, 2009-05-30 at 16:46 +0200, Vladimir 'phcoder' Serbinenko wrote:
> +#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
> +#endif
I have verified that defining APPLE_CC on Fedora would produce exactly
the same bytecode. I don't see any reason to have preprocessor
conditionals all over the place. Are you trying to support as without
variables?
> +#ifdef APPLE_CC
> + movl $(mmaphook_mmap_rel), %esi
> +#else
> movw $(DS(mmaphook_mmap)), %si
> +#endif
That's not an equivalent replacement. The argument width is different.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6/18] define asm constant for absolute memory access
2009-06-16 1:28 ` Pavel Roskin
@ 2009-06-16 10:49 ` Vladimir 'phcoder' Serbinenko
2009-08-13 5:03 ` Pavel Roskin
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-06-16 10:49 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1408 bytes --]
On Tue, Jun 16, 2009 at 3:28 AM, Pavel Roskin <proski@gnu.org> wrote:
> On Sat, 2009-05-30 at 16:46 +0200, Vladimir 'phcoder' Serbinenko wrote:
> > +#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
> > +#endif
>
> I have verified that defining APPLE_CC on Fedora would produce exactly
> the same bytecode. I don't see any reason to have preprocessor
> conditionals all over the place. Are you trying to support as without
> variables?
>
the problem is absolute adressing. Apple's AS issues a relocation directive
for the code of type:
mov a-b, %eax
(probably because of possibility of external aliases)
which is then too complex for linker to resolve, that's why I needed to use
constants as recommended by AS warning
>
> > +#ifdef APPLE_CC
> > + movl $(mmaphook_mmap_rel), %esi
> > +#else
> > movw $(DS(mmaphook_mmap)), %si
> > +#endif
>
> That's not an equivalent replacement. The argument width is different.
>
I know. Sometimes because of the quirks I had to replace some code with a
less logical alternative which should however work in the flow
>
> --
> Regards,
> Pavel Roskin
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: Type: text/html, Size: 2282 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6/18] define asm constant for absolute memory access
2009-06-16 10:49 ` Vladimir 'phcoder' Serbinenko
@ 2009-08-13 5:03 ` Pavel Roskin
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Roskin @ 2009-08-13 5:03 UTC (permalink / raw)
To: The development of GRUB 2
On Tue, 2009-06-16 at 12:49 +0200, Vladimir 'phcoder' Serbinenko wrote:
> > +#ifdef APPLE_CC
> > + movl $(mmaphook_mmap_rel), %esi
> > +#else
> > movw $(DS(mmaphook_mmap)), %si
> > +#endif
>
> That's not an equivalent replacement. The argument width is
> different.
> I know. Sometimes because of the quirks I had to replace some code
> with a less logical alternative which should however work in the flow
Please don't commit such changes without an explicit permissions form
the maintainers. It's very time consuming to verify such code after it
has been committed.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-08-13 5:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-30 14:46 [PATCH 6/18] define asm constant for absolute memory access Vladimir 'phcoder' Serbinenko
2009-06-16 1:28 ` Pavel Roskin
2009-06-16 10:49 ` Vladimir 'phcoder' Serbinenko
2009-08-13 5:03 ` Pavel Roskin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.