DragonFly submit List (threaded) for 2007-03
DragonFly BSD
DragonFly submit List (threaded) for 2007-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

DragonFly on Intel Mac?


From: YONETANI Tomokazu <qhwt+dfly@xxxxxxxxxx>
Date: Tue, 6 Mar 2007 22:41:49 +0900

Hi.
Although it runs fine on Parallels Desktop(an emulator), it doesn't
with BootCamp.  LiveCD stops twirling the baton prematurely.
There's been some good efforts in FreeBSD to install and boot on
MacBook Pro via BootCamp last year, and I confirmed that 6.2-RELEASE
installs and runs almost fine.  I searched through their commit log, and
ported the relavant parts (patch attached).  MacBook Pro is a legacy-free
hardware and has no keyboard controller, and the patch puts upper limit
on the amount of time to wait for the controller to be ready (or give up),
according to their commitlog.

 With this patch, it does boot past the boot loader, but it ends up
in double fault after many lines of 'sched_ithd: stray interrupt 7'.
Also I need to disable acpi driver because it fills the screen with
garbage and I can't see anything in the boot log.  I tested cdboot
and the kernel on other PCs and had no problem.  So it's probably
safe to commit.

I'm currently playing with it installed in a spare partition of
FreeBSD 6.2-RELEASE installation.  The hardest part is that even
on FreeBSD, the keyboard rarely work until the OS boots up (and I saw
this with SuSE too).  In fact it's easier edit /boot.config and
/boot/loader.conf from FreeBSD installation than keep punching the
power button :) This may or may not be BootCamp's fault.  I hope to post
a few more positive news/patch soon.

Cheers.
Index: boot/i386/cdboot/cdboot.S
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/boot/i386/cdboot/cdboot.S,v
retrieving revision 1.7
diff -u -p -r1.7 cdboot.S
--- boot/i386/cdboot/cdboot.S	13 Jan 2006 19:41:50 -0000	1.7
+++ boot/i386/cdboot/cdboot.S	27 Feb 2007 23:57:54 -0000
@@ -461,10 +461,17 @@ twiddle:	push %ax			# Save
 		ret
 
 		/*
-		 * Enable A20
+		 * Enable A20. Put upper limit on amount of time we wait for the
+		 * keyboard controller to get ready (65K x ISA access time). If
+		 * we wait more than that amount it's likely that the hardware
+		 * is legacy-free and simply doesn't have keyboard controller
+		 * and don't need enabling A20 at all.
 		 */
 seta20: 	cli				# Disable interrupts
-seta20.1:	in $0x64,%al			# Get status
+		xor %cx,%cx			# Clear
+seta20.1:	inc %cx				# Increment, overflow?
+		jz seta20.3			# Yes
+		in $0x64,%al			# Get status
 		test $0x2,%al			# Busy?
 		jnz seta20.1			# Yes
 		mov $0xd1,%al			# Command: Write
@@ -474,7 +481,7 @@ seta20.2:	in $0x64,%al			# Get status
 		jnz seta20.2			# Yes
 		mov $0xdf,%al			# Enable
 		out %al,$0x60			#  A20
-		sti				# Enable interrupts
+seta20.3:	sti				# Enable interrupts
 		ret				# To caller
 
 		/*
Index: boot/i386/pxeldr/pxeldr.S
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/boot/i386/pxeldr/pxeldr.S,v
retrieving revision 1.4
diff -u -p -r1.4 pxeldr.S
--- boot/i386/pxeldr/pxeldr.S	18 Jul 2004 23:40:09 -0000	1.4
+++ boot/i386/pxeldr/pxeldr.S	28 Feb 2007 14:26:15 -0000
@@ -234,10 +234,17 @@ putc:		movw $0x7,%bx			# attribute for o
 		jmp putstr			# keep looping
 
 		/*
-		 * Enable A20
+		 * Enable A20. Put upper limit on amount of time we wait for the
+		 * keyboard controller to get ready (65K x ISA access time). If
+		 * we wait more than that amount it's likely that the hardware
+		 * is legacy-free and simply doesn't have keyboard controller
+		 * and don't need enabling A20 at all.
 		 */
 seta20: 	cli				# Disable interrupts
-seta20.1:	inb $0x64,%al			# Get status
+		xor %cx,%cx			# Clear
+seta20.1:	inc %cx				# Increment, overflow?
+		jz seta20.3			# Yes
+		inb $0x64,%al			# Get status
 		testb $0x2,%al			# Busy?
 		jnz seta20.1			# Yes
 		movb $0xd1,%al			# Command: Write
@@ -247,7 +254,7 @@ seta20.2:	inb $0x64,%al			# Get status
 		jnz seta20.2			# Yes
 		movb $0xdf,%al			# Enable
 		outb %al,$0x60			#  A20
-		sti				# Enable interrupts
+seta20.3:	sti				# Enable interrupts
 		retw				# To caller
 
 		/*
Index: dev/misc/atkbdc_layer/atkbdc_isa.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/dev/misc/atkbdc_layer/atkbdc_isa.c,v
retrieving revision 1.7
diff -u -p -r1.7 atkbdc_isa.c
--- dev/misc/atkbdc_layer/atkbdc_isa.c	22 Dec 2006 23:26:17 -0000	1.7
+++ dev/misc/atkbdc_layer/atkbdc_isa.c	28 Feb 2007 12:30:00 -0000
@@ -101,6 +101,12 @@ atkbdc_probe(device_t dev)
 	struct resource	*port1;
 	int		error;
 	int		rid;
+#if defined(__i386__)
+	bus_space_tag_t	tag;
+	bus_space_handle_t ioh1;
+	volatile int	i;
+	register_t	flags;
+#endif
 
 	/* check PnP IDs */
 	if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
@@ -126,6 +132,30 @@ atkbdc_probe(device_t dev)
 		return ENXIO;
 	}
 
+#if defined(__i386__)
+	/*
+	 * Check if we really have AT keyboard controller. Poll status
+	 * register until we get "all clear" indication. If no such
+	 * indication comes, it probably means that there is no AT
+	 * keyboard controller present. Give up in such case. Check relies
+	 * on the fact that reading from non-existing in/out port returns
+	 * 0xff on i386. May or may not be true on other platforms.
+	 */
+	tag = rman_get_bustag(port0);
+	ioh1 = rman_get_bushandle(port1);
+	flags = intr_disable();
+	for (i = 0; i != 65535; i++) {
+		if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0)
+			break;
+	}
+	intr_restore(flags);
+	if (i == 65535) {
+		bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
+		bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
+		return ENXIO;
+	}
+#endif
+
 	error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
 
 	bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
Index: cpu/i386/include/cpufunc.h
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/cpu/i386/include/cpufunc.h,v
retrieving revision 1.19
diff -u -p -r1.19 cpufunc.h
--- cpu/i386/include/cpufunc.h	7 Jan 2007 00:43:22 -0000	1.19
+++ cpu/i386/include/cpufunc.h	28 Feb 2007 12:27:12 -0000
@@ -677,6 +677,22 @@ load_dr7(u_int sel)
 	__asm __volatile("movl %0,%%dr7" : : "r" (sel));
 }
 
+static __inline register_t
+intr_disable(void)
+{
+	register_t eflags;
+
+	eflags = read_eflags();
+	cpu_disable_intr();
+	return (eflags);
+}
+
+static __inline void
+intr_restore(register_t eflags)
+{
+	write_eflags(eflags);
+}
+
 #else /* !__GNUC__ */
 
 int	breakpoint	(void);


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]