Index: serverboot/Makefile
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/Makefile,v
retrieving revision 1.13
diff -u -r1.13 Makefile
--- serverboot/Makefile	23 May 2002 21:44:51 -0000	1.13
+++ serverboot/Makefile	9 Aug 2003 12:04:14 -0000
@@ -27,13 +27,15 @@
 	disk_inode.h file_io.h minix_super.h mach-exec.h
 EXTRA_DIST = def_pager_setup.c default_pager.c kalloc.c
 target = serverboot
-HURDLIBS = threads
+# HURDLIBS = threads
+HURDLIBS = 
 installationdir = $(bootdir)
 
 UNZIP_OBJS = unzip.o inflate.o util.o do-bunzip2.o
 OBJS = $(subst .c,.o,$(SRCS)) \
        boot_script.o userland-boot.o \
-       $(UNZIP_OBJS)
+       $(UNZIP_OBJS) \
+       excServer.o
 
 include ../Makeconf
 
Index: serverboot/bootstrap.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/bootstrap.c,v
retrieving revision 1.23
diff -u -r1.23 bootstrap.c
--- serverboot/bootstrap.c	2 Jun 2002 21:46:22 -0000	1.23
+++ serverboot/bootstrap.c	9 Aug 2003 12:04:15 -0000
@@ -48,10 +48,10 @@
 #else
 vm_size_t	cthread_stack_size = 8 * 1024;
 #endif
-#endif
 
 extern
 vm_size_t	cthread_wait_stack_size;
+#endif
 
 mach_port_t	bootstrap_master_device_port;	/* local name */
 mach_port_t	bootstrap_master_host_port;	/* local name */
@@ -61,9 +61,16 @@
 char	*root_name;
 char	boot_script_name[MAXPATHLEN];
 
+#if 0
 extern void	default_pager();
 extern void	default_pager_initialize();
 extern void	default_pager_setup();
+#endif
+
+#ifdef OSFMACH
+kernel_boot_info_t boot_info;  /* Contains the root name.  */
+mach_port_t exception_port;
+#endif
 
 /*
  * Convert ASCII to integer.
@@ -124,7 +131,14 @@
 {
   mach_port_t cons;
   kern_return_t rc;
+#ifdef OSFMACH
+  mach_msg_type_number_t cnt = TASK_SECURITY_TOKEN_COUNT;
+  security_token_t sec_token = KERNEL_SECURITY_TOKEN_VALUE;
+  rc = device_open (master, MACH_PORT_NULL, D_READ | D_WRITE,
+		    sec_token, "console", &cons);
+#else
   rc = device_open (master, D_READ|D_WRITE, "console", &cons);
+#endif  /* OSFMACH */
   if (rc)
     while (1) {
       volatile int x = 0;
@@ -195,11 +209,41 @@
 	boolean_t		ask_boot_script = 0;
 	boolean_t		ask_root_name = 0;
 
+#if 0
 	/*
 	 * Use 4Kbyte cthread wait stacks.
 	 */
 	cthread_wait_stack_size = 4 * 1024;
+#endif
 
+#ifdef OSFMACH
+	if (!argc)
+	  {
+	    /* We are the bootstrap task.  */
+	    mach_port_t bootstrap, wired_ledger, paged_ledger, security;
+	    
+	    result = task_get_bootstrap_port (mach_task_self (), &bootstrap);
+	    if (result)
+	      panic ("bootstrap: can't get bootstrap port\n");
+	    result = bootstrap_ports (bootstrap, &bootstrap_master_host_port,
+				      &bootstrap_master_device_port,
+				      &wired_ledger, &paged_ledger, &security);
+	    if (result)
+	      panic ("bootstrap: can't get privileged ports\n");
+	    mach_port_deallocate (mach_task_self (), wired_ledger);
+	    mach_port_deallocate (mach_task_self (), paged_ledger);
+	    mach_port_deallocate (mach_task_self (), security);
+	  
+	    host_get_boot_info (bootstrap_master_host_port, boot_info);
+	    *strchr (boot_info, ' ') = '\0';
+	    root_name = boot_info;  /* "hd0g" */
+	    flag_string = "-";  /* XXX */
+	  }
+	else if (argc < 2 || argv[1][0] != '-')
+	  panic ("bootstrap: no flags");
+	else
+	  flag_string = argv[1];
+#else
 	/*
 	 * Arg 1 is flags
 	 */
@@ -207,6 +251,7 @@
 	  panic("bootstrap: no flags");
 
 	flag_string = argv[1];
+#endif  /* OSFMACH */
 
 	/*
 	 * Parse the arguments.
@@ -246,6 +291,21 @@
 #endif
 
 
+#if 1
+	printf ("(serverboot): started\n");
+	if (mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
+				&exception_port)
+	    || mach_port_insert_right (mach_task_self (), exception_port,
+				       exception_port, MACH_MSG_TYPE_MAKE_SEND)
+	    || task_set_exception_ports (mach_task_self (), EXC_MASK_ALL &
+					 ~(EXC_MASK_SYSCALL | EXC_MASK_MACH_SYSCALL
+					   | EXC_MASK_RPC_ALERT), exception_port,
+					 EXCEPTION_STATE_IDENTITY,
+					 MACHINE_THREAD_STATE))
+	  fprintf (stderr, "warning: can't set exception port\n");
+#endif
+
+
 	/*
 	 * If the '-a' (ask) switch was specified, or if no
 	 * root device was specificed, ask for the root device.
@@ -403,6 +463,14 @@
 	}
 #endif
 
+#if 1
+	for (;;) {
+	  extern int exc_server (mach_msg_header_t *in,
+				    mach_msg_header_t *out);
+	  (void) mach_msg_server (exc_server, 4096, exception_port);
+	}
+#endif
+	
 	printf ("(serverboot): terminating\n");
 	while (1)
 	  task_terminate (mach_task_self ());
@@ -434,5 +502,67 @@
 	break;
       line = ++p;
     }
-  free (buf);
+}
+
+/* Exception handling */
+kern_return_t
+catch_exception_raise (mach_port_t exception_port,
+		       mach_port_t thread,
+		       mach_port_t task,
+		       exception_type_t exception,
+		       exception_data_t code,
+		       mach_msg_type_number_t codeCnt)
+{
+  printf ("(serverboot)catch_exception_raise(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
+}
+
+kern_return_t
+catch_exception_raise_state (mach_port_t exception_port,
+			     exception_type_t exception,
+			     exception_data_t code,
+			     mach_msg_type_number_t codeCnt,
+			     int *flavor,
+			     thread_state_t old_state,
+			     mach_msg_type_number_t old_stateCnt,
+			     thread_state_t new_state,
+			     mach_msg_type_number_t *new_stateCnt)
+{
+  printf ("(serverboot)catch_exception_raise_state(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
+}
+
+kern_return_t
+catch_exception_raise_state_identity (mach_port_t exception_port,
+				      mach_port_t thread,
+				      mach_port_t task,
+				      exception_type_t exception,
+				      exception_data_t code,
+				      mach_msg_type_number_t codeCnt,
+				      int *flavor,
+				      thread_state_t old_state,
+				      mach_msg_type_number_t old_stateCnt,
+				      thread_state_t new_state,
+				      mach_msg_type_number_t *new_stateCnt)
+{
+  struct ppc_thread_state *s = (struct ppc_thread_state *)old_state;
+  printf ("\n(serverboot)catch_exception_raise_state_identity(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  printf ("task = %i, thread = %i\n", task, thread);
+  printf ("srr0=%#x\tsrr1=%#x\n", s->srr0, s->srr1);
+  printf ("r0 =%#10x\tr1 =%#10x\tr2 =%#10x\tr3 =%#10x\n", s->r0, s->r1, s->r2, s->r3);
+  printf ("r4 =%#10x\tr5 =%#10x\tr6 =%#10x\tr7 =%#10x\n", s->r4, s->r5, s->r6, s->r7);
+  printf ("r8 =%#10x\tr9 =%#10x\tr10=%#10x\tr11=%#10x\n", s->r8, s->r9, s->r10, s->r11);
+  printf ("r12=%#10x\tr13=%#10x\tr14=%#10x\tr15=%#10x\n", s->r12, s->r13, s->r14, s->r15);
+  printf ("r16=%#10x\tr17=%#10x\tr18=%#10x\tr19=%#10x\n", s->r16, s->r17, s->r18, s->r19);
+  printf ("r20=%#10x\tr21=%#10x\tr22=%#10x\tr23=%#10x\n", s->r20, s->r21, s->r22, s->r23);
+  printf ("r24=%#10x\tr25=%#10x\tr26=%#10x\tr27=%#10x\n", s->r24, s->r25, s->r26, s->r27);
+  printf ("r28=%#10x\tr29=%#10x\tr30=%#10x\tr31=%#10x\n", s->r28, s->r29, s->r30, s->r31);
+  printf ("cr =%#10x\txer=%#10x\tlr =%#10x\tctr=%#10x\n", s->cr, s->xer, s->lr, s->ctr);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
 }
Index: serverboot/bunzip2.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/bunzip2.c,v
retrieving revision 1.1
diff -u -r1.1 bunzip2.c
--- serverboot/bunzip2.c	30 Apr 1999 11:04:07 -0000	1.1
+++ serverboot/bunzip2.c	9 Aug 2003 12:04:15 -0000
@@ -22,7 +22,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <setjmp.h>
+#if 0
 #include <cthreads.h>
+#endif
 #include <errno.h>
 
 #include <file_io.h>
Index: serverboot/def_pager_setup.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/def_pager_setup.c,v
retrieving revision 1.5
diff -u -r1.5 def_pager_setup.c
--- serverboot/def_pager_setup.c	11 Jan 2001 22:32:35 -0000	1.5
+++ serverboot/def_pager_setup.c	9 Aug 2003 12:04:15 -0000
@@ -99,7 +99,7 @@
 default_pager_paging_storage (mach_port_t pager,
                               mach_port_t device,
                               recnum_t *runs, mach_msg_type_number_t nrun,
-                              default_pager_filename_t name,
+			      char *name,
                               boolean_t add)
 {
   return MIG_BAD_ID;
Index: serverboot/default_pager.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/default_pager.c,v
retrieving revision 1.27
diff -u -r1.27 default_pager.c
--- serverboot/default_pager.c	14 Jun 2002 21:47:12 -0000	1.27
+++ serverboot/default_pager.c	9 Aug 2003 12:04:17 -0000
@@ -2429,10 +2429,25 @@
 	 *	until we unlock the object.
 	 */
 
+#ifdef OLD_MEMORY_OBJECT_ATTRIBUTE_INFO
+	{
+	  struct old_memory_object_attr_info attr = {
+	    object_ready: TRUE,
+	    may_cache: FALSE,
+	    copy_strategy: default_pager_copy_strategy
+	  };
+	  kr = memory_object_change_attributes (pager_request,
+						OLD_MEMORY_OBJECT_ATTRIBUTE_INFO,
+						&attr,
+						OLD_MEMORY_OBJECT_ATTR_INFO_COUNT,
+						MACH_PORT_NULL);
+	}
+#else
 	kr = memory_object_set_attributes(pager_request,
 					  TRUE,
 					  FALSE,	/* do not cache */
 					  default_pager_copy_strategy);
+#endif
 	if (kr != KERN_SUCCESS)
 	    panic(here, my_name);
 
@@ -2668,10 +2683,17 @@
 			VM_PROT_NONE,
 			FALSE, MACH_PORT_NULL);
 		} else {
+#ifdef OSFMACH
+		    (void) memory_object_data_supply (reply_to, offset,
+						      addr, vm_page_size,
+						      FALSE, VM_PROT_NONE,
+						      FALSE, MACH_PORT_NULL);
+#else
 		    (void) memory_object_data_provided(
 			reply_to, offset,
 			addr, vm_page_size,
 			VM_PROT_NONE);
+#endif
 		}
 		break;
 
@@ -2955,8 +2977,44 @@
 	boolean_t	dirty;
 	boolean_t	kernel_copy;
 {
-	panic("%sdata_return",my_name);
-	return(KERN_FAILURE);
+	vm_size_t amount_sent;
+	default_pager_t ds;
+	kern_return_t err;
+
+	ds = pager_port_lookup (pager);
+	assert (ds != DEFAULT_PAGER_NULL);
+
+	pager_port_lock (ds, seqno);
+	pager_port_check_request (ds, pager_request);
+	pager_port_start_write (ds);
+	pager_port_unlock (ds);
+
+	for (amount_sent = 0;
+	     amount_sent < data_cnt;
+	     amount_sent += vm_page_size)
+	  {
+	    kern_return_t result;
+
+	    result = default_write (&ds->dpager,
+				    addr + amount_sent,
+				    vm_page_size,
+				    offset + amount_sent);
+	    if (result != KERN_SUCCESS)
+	      {
+		printf ("data_return: write error %#x\n", result);
+		dstruct_lock (ds);
+		ds->errors++;
+		dstruct_unlock (ds);
+	      }
+	    default_pager_pageout_count++;
+	  }
+
+	pager_port_finish_write (ds);
+	err = vm_deallocate (default_pager_self, addr, data_cnt);
+	if (err != KERN_SUCCESS)
+	  panic ("%s data_return", my_name);
+	
+	return KERN_SUCCESS;
 }
 
 kern_return_t
@@ -2970,6 +3028,30 @@
 	return(KERN_FAILURE);
 }
 
+#ifdef OSFMACH
+kern_return_t
+seqnos_memory_object_synchronize (memory_object_t pager,
+				  mach_port_seqno_t seqno,
+				  mach_port_t memory_control,
+				  vm_offset_t offset,
+				  vm_size_t length,
+				  vm_sync_t flags)
+{
+  panic ("%ssynchronize", my_name);
+  return KERN_FAILURE;
+}
+
+kern_return_t
+seqnos_memory_object_discard_request (memory_object_t pager,
+				      mach_port_seqno_t seqno,
+				      mach_port_t memory_control,
+				      vm_offset_t offset,
+				      vm_size_t length)
+{
+  panic ("%sdiscard_request", my_name);
+  return KERN_FAILURE;
+}
+#endif
 
 boolean_t default_pager_notify_server(in, out)
 	mach_msg_header_t *in, *out;
@@ -2993,14 +3075,23 @@
 	assert(n->not_header.msgh_size == sizeof *n);
 	assert(n->not_header.msgh_remote_port == MACH_PORT_NULL);
 
+#ifdef MACH_MSG_TYPE_INTEGER_32
 	assert(n->not_type.msgt_name == MACH_MSG_TYPE_INTEGER_32);
 	assert(n->not_type.msgt_size == 32);
 	assert(n->not_type.msgt_number == 1);
 	assert(n->not_type.msgt_inline);
 	assert(! n->not_type.msgt_longform);
+#endif
 
 	default_pager_no_senders(n->not_header.msgh_local_port,
-				 n->not_header.msgh_seqno, n->not_count);
+#ifdef MACH_MSG_TRAILER_FORMAT_0
+				 /* OSF Mach sends the seqno in the
+				    trailer of the message.  */
+				 n->trailer.msgh_seqno,
+#else
+				 n->not_header.msgh_seqno,
+#endif
+				 n->not_count);
 
 	out->msgh_remote_port = MACH_PORT_NULL;
 	return TRUE;
@@ -3159,14 +3250,14 @@
 
 	dpt = (default_pager_thread_t *) kalloc(sizeof *dpt);
 	if (dpt == 0)
-		panic(my_name);
+		panic("%s: start_default_pager_thread: kalloc", my_name);
 
 	dpt->dpt_internal = internal;
 
 	kr = vm_allocate(default_pager_self, &dpt->dpt_buffer,
 			 vm_page_size, TRUE);
 	if (kr != KERN_SUCCESS)
-		panic(my_name);
+		panic("%s: start_default_pager_thread: vm_allocate", my_name);
 	wire_memory(dpt->dpt_buffer, vm_page_size,
 		    VM_PROT_READ|VM_PROT_WRITE);
 
@@ -3193,10 +3284,25 @@
 	if (kr != KERN_SUCCESS)
 		panic(my_name);
 
+#if 1
+	/* Get a send right for vm_set_default_memory_manager.  */
+	mach_port_insert_right (default_pager_self,
+				default_pager_default_port,
+				default_pager_default_port,
+				MACH_MSG_TYPE_MAKE_SEND);
+#endif
+	
 	DMM = default_pager_default_port;
 	kr = vm_set_default_memory_manager(host_port, &DMM);
 	if ((kr != KERN_SUCCESS) || MACH_PORT_VALID(DMM))
-		panic(my_name);
+		panic("%s vm_set_default_memory_manager: %s\n", my_name,
+		      strerror (kr));
+
+#if 1
+	/* Release the extra send right.  */
+	mach_port_mod_refs (default_pager_self, default_pager_default_port,
+			    MACH_PORT_RIGHT_SEND, -1);
+#endif
 
 	/*
 	 *	Initialize the exception port.
@@ -3241,11 +3347,17 @@
 	kern_return_t kr;
 	int i;
 
+#if 0
+	printf ("default_pager_thread_privileges\n");
+#endif
 	default_pager_thread_privileges();
 
 	/*
 	 * Wire down code, data, stack
 	 */
+#if 0
+	printf ("wire_all_memory\n");
+#endif
 	wire_all_memory();
 
 
@@ -3292,6 +3404,9 @@
 	for (i = 0; i < default_pager_external_count; i++)
 		start_default_pager_thread(FALSE);
 
+#if 0
+	printf ("default_pager_default_thread\n");
+#endif
 	default_pager_default_thread(0); /* Become the default_pager server */
 #if 0
 	cthread_fork (default_pager_default_thread, 0);
@@ -3768,7 +3883,11 @@
 default_pager_paging_file(pager, mdport, file_name, add)
 	mach_port_t			pager;
 	mach_port_t			mdport;
+#ifdef OSFMACH
+	char *				file_name;
+#else
 	default_pager_filename_t	file_name;
+#endif
 	boolean_t			add;
 {
 	kern_return_t   kr;
@@ -3891,16 +4010,63 @@
  */
 
 kern_return_t
-catch_exception_raise(exception_port, thread, task, exception, code, subcode)
-	mach_port_t exception_port;
-	mach_port_t thread, task;
-	int exception, code, subcode;
-{
-	ddprintf ("(default_pager)catch_exception_raise(%d,%d,%d)\n",
-	       exception, code, subcode);
-	panic(my_name);
+catch_exception_raise (mach_port_t exception_port,
+		       mach_port_t thread,
+		       mach_port_t task,
+#ifdef EXC_MASK_ALL	/* New interface flavor.  */
+		       exception_type_t exception,
+		       exception_data_t code,
+		       mach_msg_type_number_t codeCnt
+#else			/* Vanilla Mach 3.0 interface.  */
+		       int exception,
+		       int code,
+		       int subcode
+#endif
+		       )
+{
+  ddprintf ("(default_pager)catch_exception_raise(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  panic (my_name);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
+}
 
-	/* mach_msg_server will deallocate thread/task for us */
+#ifdef EXC_MASK_ALL
+kern_return_t
+catch_exception_raise_state (mach_port_t exception_port,
+			     exception_type_t exception,
+			     exception_data_t code,
+			     mach_msg_type_number_t codeCnt,
+			     int *flavor,
+			     thread_state_t old_state,
+			     mach_msg_type_number_t old_stateCnt,
+			     thread_state_t new_state,
+			     mach_msg_type_number_t *new_stateCnt)
+{
+  ddprintf ("(default_pager)catch_exception_raise_state(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  panic (my_name);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
+}
 
-	return KERN_FAILURE;
+kern_return_t
+catch_exception_raise_state_identity (mach_port_t exception_port,
+				      mach_port_t thread,
+				      mach_port_t task,
+				      exception_type_t exception,
+				      exception_data_t code,
+				      mach_msg_type_number_t codeCnt,
+				      int *flavor,
+				      thread_state_t old_state,
+				      mach_msg_type_number_t old_stateCnt,
+				      thread_state_t new_state,
+				      mach_msg_type_number_t *new_stateCnt)
+{
+  ddprintf ("\n(default_pager)catch_exception_raise_state_identity(%d,%d,%d)\n",
+	  exception, code[0], code[1]);
+  panic (my_name);
+  /* mach_msg_server will deallocate thread/task for us */
+  return KERN_FAILURE;
 }
+#endif
Index: serverboot/elf-load.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/elf-load.c,v
retrieving revision 1.5
diff -u -r1.5 elf-load.c
--- serverboot/elf-load.c	3 Jul 2002 19:35:03 -0000	1.5
+++ serverboot/elf-load.c	9 Aug 2003 12:04:17 -0000
@@ -52,6 +52,10 @@
 # define MY_CLASS	ELFCLASS32
 # define MY_DATA	ELFDATA2LSB
 # define MY_MACHINE	EM_386
+#elif defined powerpc
+# define MY_CLASS	ELFCLASS32
+# define MY_DATA	ELFDATA2MSB
+# define MY_MACHINE	EM_PPC
 #elif defined __alpha__
 # define MY_CLASS	ELFCLASS64
 # define MY_DATA	ELFDATA2LSB
Index: serverboot/exec.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/exec.c,v
retrieving revision 1.3
diff -u -r1.3 exec.c
--- serverboot/exec.c	23 Jun 2002 04:29:14 -0000	1.3
+++ serverboot/exec.c	9 Aug 2003 12:04:17 -0000
@@ -23,10 +23,6 @@
  * any improvements or extensions that they make and grant Carnegie Mellon
  * the rights to redistribute these changes.
  */
-/*
- * i386-specific routines for loading a.out files.
- */
-
 #include <mach.h>
 #include <mach/machine/vm_param.h>
 #include "mach-exec.h"
@@ -35,6 +31,10 @@
 
 #ifdef i386
 
+/*
+ * i386-specific routines for loading a.out files.
+ */
+
 #include <mach/machine/eflags.h>
 
 /*
@@ -87,6 +87,36 @@
 				reg_size);
 
 	return (char *)regs.uesp;
+}
+
+#elif defined powerpc
+
+#define STACK_SIZE (64 * 1024)
+
+char *set_regs (mach_port_t user_task,
+		mach_port_t user_thread,
+		struct exec_info *info,
+		int arg_size)
+{
+  vm_offset_t stack_start;
+  vm_offset_t stack_end;
+  struct ppc_thread_state regs;
+  unsigned int reg_size;
+
+  stack_end = VM_MAX_ADDRESS;
+  stack_start = VM_MAX_ADDRESS - STACK_SIZE;
+  (void) vm_allocate (user_task, &stack_start, STACK_SIZE, FALSE);
+
+  reg_size = PPC_THREAD_STATE_COUNT;
+  (void) thread_get_state (user_thread, PPC_THREAD_STATE,
+			   (thread_state_t) &regs, &reg_size);
+  regs.srr0 = info->entry;
+  regs.r1 = (int) ((stack_end - arg_size) & ~(sizeof (int) - 1));
+
+  (void) thread_set_state (user_thread, PPC_THREAD_STATE,
+			   (thread_state_t) &regs, reg_size);
+
+  return (char *) regs.r1;
 }
 
 #elif defined __alpha__
Index: serverboot/ext2_file_io.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/ext2_file_io.c,v
retrieving revision 1.5
diff -u -r1.5 ext2_file_io.c
--- serverboot/ext2_file_io.c	21 Jul 2001 05:19:15 -0000	1.5
+++ serverboot/ext2_file_io.c	9 Aug 2003 12:04:21 -0000
@@ -36,6 +36,24 @@
 #include "file_io.h"
 #include "ffs_compat.h"
 
+#include <endian.h>
+
+/*
+extern int strprefix (char *s1, char *s2);
+extern int file_is_structured (struct file *fp);
+*/
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+/* ext2 filesystem is in little-endian format.  */
+/*
+#define SW16(x) do { (x) = ((((x) & 0xff) << 8) | ((x) >> 8)); } while (0)
+#define SW32(x) do { (x) = (((x) << 24) | (((x) & 0xff00) << 8) \
+			    | (((x) & 0xff0000) >> 8) | (((x) >> 24))); } while (0)
+*/
+#define SW16(x) do { (x) = le16_to_cpu (x); } while (0)
+#define SW32(x) do { (x) = le32_to_cpu (x); } while (0)
+#endif  /* __BIG_ENDIAN */
+
 void	ext2_close_file();	/* forward */
 
 /*
@@ -87,8 +105,10 @@
 	daddr_t			disk_block;
 	kern_return_t		rc;
 
+	/* printf ("read_inode (%u)\n", (unsigned int) inumber); */
 	fs = fp->f_fs;
 	disk_block = ino2blk(fs, fp->f_gd, inumber);
+	/* printf ("disk_block = %u\n", (unsigned int) disk_block); */
 
 	rc = device_read(fp->f_dev,
 			 0,
@@ -104,6 +124,42 @@
 
 	    dp = (struct ext2_inode *)buf;
 	    dp += itoo(fs, inumber);
+#if __BYTE_ORDER == __BIG_ENDIAN
+	    SW16 (dp->i_mode);
+	    SW16 (dp->i_uid);
+	    SW32 (dp->i_size);
+	    SW32 (dp->i_atime);
+	    SW32 (dp->i_ctime);
+	    SW32 (dp->i_mtime);
+	    SW32 (dp->i_dtime);
+	    SW16 (dp->i_gid);
+	    SW16 (dp->i_links_count);
+	    SW32 (dp->i_blocks);
+	    SW32 (dp->i_flags);
+	    /*
+	    printf ("mode=0%o uid=%i size=%i atime=0x%x ctime=0x%x mtime=0x%x dtime=0x%x\n",
+		    dp->i_mode, dp->i_uid, dp->i_size, dp->i_atime, dp->i_ctime,
+		    dp->i_mtime, dp->i_dtime);
+	    */
+	    SW32 (dp->osd1.hurd1.h_i_translator);
+#if 0
+	    /* Don't swap the block numbers, they might be used
+	       for a fast symlink.  */
+	    {
+	      int i;
+	      for (i = 0; i < EXT2_N_BLOCKS; i++)
+		SW32 (dp->i_block[i]);
+	    }
+#endif
+	    SW32 (dp->i_generation);
+	    SW32 (dp->i_file_acl);
+	    SW32 (dp->i_dir_acl);
+	    SW32 (dp->i_faddr);
+	    SW16 (dp->osd2.hurd2.h_i_mode_high);
+	    SW16 (dp->osd2.hurd2.h_i_uid_high);
+	    SW16 (dp->osd2.hurd2.h_i_gid_high);
+	    SW32 (dp->osd2.hurd2.h_i_author);
+#endif  /* __BIG_ENDIAN */
 	    fp->i_ic = *dp;
 	    fp->f_size = dp->i_size;
 	}
@@ -167,7 +223,7 @@
 
 	if (file_block < NDADDR) {
 	    /* Direct block. */
-	    *disk_block_p = fp->i_ic.i_block[file_block];
+	    *disk_block_p = le32_to_cpu (fp->i_ic.i_block[file_block]);
 	    mutex_unlock(&fp->f_lock);
 	    return (0);
 	}
@@ -191,7 +247,7 @@
 	    return (FS_NOT_IN_FILE);
 	}
 
-	ind_block_num = fp->i_ic.i_block[level + NDADDR];
+	ind_block_num = le32_to_cpu (fp->i_ic.i_block[level + NDADDR]);
 
 	/*
 	 * Initialize array of blocks to free.
@@ -267,6 +323,9 @@
 		idx = file_block;
 
 	    ind_block_num = ((daddr_t *)data)[idx];
+#if __BYTE_ORDER == __BIG_ENDIAN
+	    SW32 ((__u32)ind_block_num);
+#endif
 	}
 
 	mutex_unlock(&fp->f_lock);
@@ -379,6 +438,7 @@
 	kern_return_t	rc;
 	char		tmp_name[256];
 
+	/* printf ("Looking for entry `%s'\n", name); */
 	length = strlen(name);
 
 	offset = 0;
@@ -388,18 +448,27 @@
 		return (rc);
 
 	    dp = (struct ext2_dir_entry_2 *)buf;
+#if __BYTE_ORDER == __BIG_ENDIAN
+	    /*
+	    SW32 (dp->inode);
+	    SW16 (dp->rec_len);
+	    */
+#endif
 	    if (dp->inode != 0) {
 		strncpy (tmp_name, dp->name, dp->name_len);
 		tmp_name[dp->name_len] = '\0';
+		/* printf ("entry: %s\n", tmp_name); */
 		if (dp->name_len == length &&
 		    !strcmp(name, tmp_name))
 	    	{
 		    /* found entry */
-		    *inumber_p = dp->inode;
+		    /* printf ("`%s' is inode %u (LE)\n", tmp_name, dp->inode); */
+		    *inumber_p = le32_to_cpu (dp->inode);
+		    /* printf ("`%s' is inode %u\n", name, *(unsigned int *)inumber_p); */
 		    return (0);
 		}
 	    }
-	    offset += dp->rec_len;
+	    offset += le16_to_cpu (dp->rec_len);
 	}
 	return (FS_NO_ENTRY);
 }
@@ -423,6 +492,7 @@
 	int			gd_size;
 	int			gd_location;
 	int			gd_sector;
+	/* printf ("read_fs ()\n"); */
 
 	/*
 	 * Read the super block
@@ -436,8 +506,42 @@
 	 * Check the superblock
 	 */
 	fs = (struct ext2_super_block *)buf;
+#if __BYTE_ORDER == __BIG_ENDIAN
+	SW32 (fs->s_inodes_count);
+	SW32 (fs->s_blocks_count);
+	SW32 (fs->s_r_blocks_count);
+	SW32 (fs->s_free_blocks_count);
+	SW32 (fs->s_free_inodes_count);
+	SW32 (fs->s_first_data_block);
+	SW32 (fs->s_log_block_size);
+	SW32 ((__u32)fs->s_log_frag_size);
+	SW32 (fs->s_blocks_per_group);
+	SW32 (fs->s_frags_per_group);
+	SW32 (fs->s_inodes_per_group);
+	SW32 (fs->s_mtime);
+	SW32 (fs->s_wtime);
+	SW16 (fs->s_mnt_count);
+	SW16 ((__u32)fs->s_max_mnt_count);
+	SW16 (fs->s_magic);
+	SW16 (fs->s_state);
+	SW16 (fs->s_errors);
+	SW16 (fs->s_minor_rev_level);
+	SW32 (fs->s_lastcheck);
+	SW32 (fs->s_checkinterval);
+	SW32 (fs->s_creator_os);
+	SW32 (fs->s_rev_level);
+	SW16 (fs->s_def_resuid);
+	SW16 (fs->s_def_resgid);
+	SW16 (fs->s_inode_size);
+	SW16 (fs->s_block_group_nr);
+	SW32 (fs->s_feature_compat);
+	SW32 (fs->s_feature_incompat);
+	SW32 (fs->s_feature_ro_compat);
+	SW32 (fs->s_algorithm_usage_bitmap);
+#endif  /* __BIG_ENDIAN */
 	if (fs->s_magic != EXT2_SUPER_MAGIC) {
 		(void) vm_deallocate(mach_task_self(), buf, buf_size);
+		/* printf ("bad magic\n"); */
 		return (FS_INVALID_FS);
 	}
 
@@ -448,6 +552,7 @@
 	 */
 	gd_count = (fs->s_blocks_count - fs->s_first_data_block +
 		    fs->s_blocks_per_group - 1) / fs->s_blocks_per_group;
+	/* printf ("%i group descriptors\n", gd_count); */
 	gd_blocks = (gd_count + EXT2_DESC_PER_BLOCK(fs) - 1) /
 		    EXT2_DESC_PER_BLOCK(fs);
 	gd_size = gd_blocks * EXT2_BLOCK_SIZE(fs);
@@ -461,12 +566,27 @@
 			    (char **) &buf2, &buf2_size);
 	if (error) {
 		(void) vm_deallocate(mach_task_self(), buf, buf_size);
+		/* printf ("can't read from device\n"); */
 		return error;
 	}
 
 	*gdp = (struct ext2_group_desc *) buf2;
+#if __BYTE_ORDER == __BIG_ENDIAN
+	{
+	  int i;
+	  for (i = 0; i < gd_count; i++) {
+	    SW32 ((*gdp)[i].bg_block_bitmap);
+	    SW32 ((*gdp)[i].bg_inode_bitmap);
+	    SW32 ((*gdp)[i].bg_inode_table);
+	    SW16 ((*gdp)[i].bg_free_blocks_count);
+	    SW16 ((*gdp)[i].bg_free_inodes_count);
+	    SW16 ((*gdp)[i].bg_used_dirs_count);
+	  }
+	}
+#endif  /* __BIG_ENDIAN */
 	*gd_size_p = gd_size;
 
+	/* printf ("read_fs: done\n"); */
 	return 0;
 }
 
@@ -533,6 +653,11 @@
 	int		nlinks = 0;
 
 	char	namebuf[MAXPATHLEN+1];
+#ifdef OSFMACH
+	security_token_t sec_token = KERNEL_SECURITY_TOKEN_VALUE;
+#endif
+
+	/* printf ("ext2_file_open (%s)\n", path); */
 
 	if (path == 0 || *path == '\0') {
 	    return FS_NO_ENTRY;
@@ -548,7 +673,7 @@
 	 * root device.
 	 */
 	if (!strprefix(namebuf, "/dev/")) {
-	    printf("no device name\n");
+	  /* printf("no device name\n"); */
 	    return FS_NO_ENTRY;
 	}
 
@@ -561,10 +686,17 @@
 
 	bzero (fp, sizeof (struct file));
 
+	/* printf ("opening device %s\n", component); */
+#ifdef OSFMACH
+	rc = device_open (master_device_port, MACH_PORT_NULL,
+			  D_READ | D_WRITE, sec_token,
+			  component, &fp->f_dev);
+#else
 	rc = device_open(master_device_port,
 			D_READ|D_WRITE,
 			component,
 			&fp->f_dev);
+#endif  /* OSFMACH */
 	if (rc)
 	    return rc;
 
@@ -575,13 +707,15 @@
 
 	*cp = c;
 
+	/* printf ("mounting filesystem\n"); */
 	rc = mount_fs(fp);
 	if (rc)
 	    return rc;
 
+	/* printf ("reading root inode\n"); */
 	inumber = (ino_t) ROOTINO;
 	if ((rc = read_inode(inumber, fp)) != 0) {
-	    printf("can't read root inode\n");
+	  /* printf("can't read root inode\n"); */
 	    goto exit;
 	}
 
@@ -590,8 +724,10 @@
 	    /*
 	     * Check that current node is a directory.
 	     */
-	    if ((fp->i_ic.i_mode & IFMT) != IFDIR)
+	    if ((fp->i_ic.i_mode & IFMT) != IFDIR) {
+	      /* printf ("notdir: %s (mode=%#x)\n", component, fp->i_ic.i_mode); */
 		RETURN (FS_NOT_DIRECTORY);
+	    }
 
 	    /*
 	     * Remove extra separators
@@ -624,7 +760,7 @@
 	    parent_inumber = inumber;
 	    rc = search_directory(component, fp, &inumber);
 	    if (rc) {
-		printf("%s: not found\n", path);
+	      /* printf("%s: not found\n", path); */
 		goto exit;
 	    }
 	    *cp = c;
@@ -711,10 +847,19 @@
 		    /*
 		     * Open new root device.
 		     */
+#ifdef OSFMACH
+		    rc = device_open (master_device_port,
+				      MACH_PORT_NULL,
+				      D_READ,
+				      sec_token,
+				      component,
+				      &fp->f_dev);
+#else
 		    rc = device_open(master_device_port,
 				D_READ,
 				component,
 				&fp->f_dev);
+#endif  /* OSFMACH */
 		    if (rc)
 			return (rc);
 
Index: serverboot/ffs_compat.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/ffs_compat.c,v
retrieving revision 1.2
diff -u -r1.2 ffs_compat.c
--- serverboot/ffs_compat.c	3 Jan 2000 20:25:04 -0000	1.2
+++ serverboot/ffs_compat.c	9 Aug 2003 12:04:21 -0000
@@ -23,7 +23,7 @@
 #include <mach/mach_traps.h>
 #include <mach/mach_interface.h>
 
-#include <file_io.h>
+#include "file_io.h"
 
 #define	EXT2_INODES_PER_BLOCK(s)	(EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))
 
@@ -32,10 +32,22 @@
         int group;
         int blk;
 
+	/*
+	printf ("%u inodes per group\n", EXT2_INODES_PER_GROUP (fs));
+	printf ("%u inodes per block\n", EXT2_INODES_PER_BLOCK (fs));
+	*/
         group = (ino - 1) / EXT2_INODES_PER_GROUP(fs);
+	/*
+	printf ("group = %i/%i = %i\n", ino - 1, EXT2_INODES_PER_GROUP (fs), group);
+	printf ("inode %u -> group %u\n", (unsigned int) ino, (unsigned int) group);
+	*/
         blk = gd[group].bg_inode_table +
 	      (((ino - 1) % EXT2_INODES_PER_GROUP(fs)) /
                EXT2_INODES_PER_BLOCK(fs));
+	/*
+	printf ("block = %u + ((%i %% %i) / %i) = %i\n", gd[group].bg_inode_table,
+		ino - 1, EXT2_INODES_PER_GROUP (fs), EXT2_INODES_PER_BLOCK (fs), blk);
+	*/
         return blk;
 }
 
Index: serverboot/ffs_compat.h
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/ffs_compat.h,v
retrieving revision 1.1
diff -u -r1.1 ffs_compat.h
--- serverboot/ffs_compat.h	3 Apr 1997 23:27:17 -0000	1.1
+++ serverboot/ffs_compat.h	9 Aug 2003 12:04:21 -0000
@@ -52,3 +52,10 @@
 #define f_blksize	u.ext2.ext2_blksize
 #define f_blkno		u.ext2.ext2_blkno
 
+extern int ino2blk (struct ext2_super_block *fs,
+		    struct ext2_group_desc *gd, int ino);
+extern int fsbtodb (struct ext2_super_block *fs, int b);
+extern int itoo (struct ext2_super_block *fs, int ino);
+extern int blkoff (struct ext2_super_block * fs, vm_offset_t offset);
+extern int lblkno (struct ext2_super_block * fs, vm_offset_t offset);
+extern int blksize (struct ext2_super_block *fs, struct file *fp, daddr_t file_block);
Index: serverboot/ffs_file_io.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/ffs_file_io.c,v
retrieving revision 1.4
diff -u -r1.4 ffs_file_io.c
--- serverboot/ffs_file_io.c	21 Jul 2001 05:19:15 -0000	1.4
+++ serverboot/ffs_file_io.c	9 Aug 2003 12:04:21 -0000
@@ -507,6 +507,9 @@
 	int		nlinks = 0;
 
 	char	namebuf[MAXPATHLEN+1];
+#ifdef OSFMACH
+	security_token_t sec_token = KERNEL_SECURITY_TOKEN_VALUE;
+#endif
 
 	if (path == 0 || *path == '\0') {
 	    return FS_NO_ENTRY;
@@ -535,10 +538,16 @@
 
 	bzero (fp, sizeof (struct file));
 
+#ifdef OSFMACH
+	rc = device_open (master_device_port, MACH_PORT_NULL,
+			  D_READ | D_WRITE, sec_token,
+			  component, &fp->f_dev);
+#else
 	rc = device_open(master_device_port,
 			D_READ|D_WRITE,
 			component,
 			&fp->f_dev);
+#endif  /* OSFMACH */
 	if (rc)
 	    return rc;
 
@@ -705,10 +714,16 @@
 		    /*
 		     * Open new root device.
 		     */
+#ifdef OSFMACH
+		    rc = device_open (master_device_port, MACH_PORT_NULL,
+				      D_READ, sec_token, component,
+				      &fp->f_dev);
+#else
 		    rc = device_open(master_device_port,
 				D_READ,
 				component,
 				&fp->f_dev);
+#endif  /* OSFMACH */
 		    if (rc)
 			return (rc);
 
Index: serverboot/file_io.h
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/file_io.h,v
retrieving revision 1.3
diff -u -r1.3 file_io.h
--- serverboot/file_io.h	3 Jan 2000 20:25:04 -0000	1.3
+++ serverboot/file_io.h	9 Aug 2003 12:04:21 -0000
@@ -45,8 +45,40 @@
 typedef u_int8_t  __u8;
 typedef int8_t    __s8;
 
+#if __BYTE_ORDER == __BIG_ENDIAN
+/* From <linux-include>/asm-ppc/byteorder.h.  */
+
+extern inline __u32 le32_to_cpu (__u32 x) __attribute__ ((const));
+extern inline __u16 le16_to_cpu (__u16 x) __attribute__ ((const));
+
+extern inline __u32
+le32_to_cpu (__u32 x)
+{
+  return ((((x) & 0x000000ffU) << 24) |
+	  (((x) & 0x0000ff00U) <<  8) |
+	  (((x) & 0x00ff0000U) >>  8) |
+	  (((x) & 0xff000000U) >> 24));
+}
+#define cpu_to_le32(x) le32_to_cpu(x)
+
+extern inline __u16
+le16_to_cpu (__u16 x)
+{
+  return ((((x) & 0x00ff) << 8) |
+	  (((x) & 0xff00) >> 8));
+}
+#define cpu_to_le16(x) le16_to_cpu(x)
+
+#else  /* __BYTE_ORDER */
+#define le32_to_cpu(x) (x)
+#define cpu_to_le32(x) (x)
+#define le16_to_cpu(x) (x)
+#define cpu_to_le16(x) (x)
+#endif  /* __BYTE_ORDER */
+
 #include <defs.h>
 #include "minix_fs.h"
+#define SB_LITTLE_ENDIAN 0  /* we convert the superblock to native format in memory */
 #include "../ext2fs/ext2_fs.h"	/* snarf stolen linux header from ext2fs */
 #include "disk_inode.h"
 
Index: serverboot/load.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/load.c,v
retrieving revision 1.11
diff -u -r1.11 load.c
--- serverboot/load.c	7 May 2003 13:42:14 -0000	1.11
+++ serverboot/load.c	9 Aug 2003 12:04:21 -0000
@@ -261,6 +261,16 @@
 
 	extern char *	strbuild();
 
+#if 1
+	{
+	  int i;
+	  printf ("boot_script_exec_cmd (task %i):", user_task);
+	  for (i = 0; i < arg_count; i++)
+	    printf (" %s", argv[i]);
+	  printf ("\n");
+	}
+#endif
+	
   	if (strcmp (file_name, "/dev/"))
 	  (void) strbuild(namebuf, "/dev/", root_name, "/", file_name,
 			  (char *)0);
@@ -274,6 +284,8 @@
 
 	result = open_file(bootstrap_master_device_port, namebuf, &file);
 	if (result != 0) {
+	  printf ("open_file returns %#x\n", result);
+	  panic ("%s: error %#x\n", namebuf, result);
 	  panic ("%s: %s", namebuf, strerror (result));
 	}
 
@@ -362,9 +374,7 @@
 #endif  /* BZIP2 */
 	if (result)
 	  panic ("cannot load %s: %s", namebuf, strerror (result));
-#if 0
 	printf("(serverboot): loaded %s; entrypoint %08x\n", namebuf, info.entry);
-#endif
 
 	/*
 	 * Set up the stack and user registers.
Index: serverboot/minix_file_io.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/minix_file_io.c,v
retrieving revision 1.2
diff -u -r1.2 minix_file_io.c
--- serverboot/minix_file_io.c	20 Jul 1999 20:02:25 -0000	1.2
+++ serverboot/minix_file_io.c	9 Aug 2003 12:04:21 -0000
@@ -502,6 +502,9 @@
 	int		nlinks = 0;
 
 	char	namebuf[MAXPATHLEN+1];
+#ifdef OSFMACH
+	security_token_t sec_token = KERNEL_SECURITY_TOKEN_VALUE;
+#endif
 
 	if (path == 0 || *path == '\0') {
 	    return FS_NO_ENTRY;
@@ -530,10 +533,16 @@
 
 	bzero (fp, sizeof (struct file));
 
+#ifdef OSFMACH
+	rc = device_open (master_device_port, MACH_PORT_NULL,
+			  D_READ | D_WRITE, sec_token,
+			  component, &fp->f_dev);
+#else
 	rc = device_open(master_device_port,
 			D_READ|D_WRITE,
 			component,
 			&fp->f_dev);
+#endif  /* OSFMACH */
 	if (rc)
 	    return rc;
 
Index: serverboot/panic.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/panic.c,v
retrieving revision 1.4
diff -u -r1.4 panic.c
--- serverboot/panic.c	21 Jul 2001 05:17:53 -0000	1.4
+++ serverboot/panic.c	9 Aug 2003 12:04:21 -0000
@@ -42,6 +42,7 @@
 {
 	va_list listp;
 
+	printf ("panic\n");
 	clearerr (stdout);
 	printf("%s: panic: ", program_invocation_name);
 	va_start(listp, s);
Index: serverboot/wiring.c
===================================================================
RCS file: /cvsroot/hurd/hurd/serverboot/wiring.c,v
retrieving revision 1.4
diff -u -r1.4 wiring.c
--- serverboot/wiring.c	18 Nov 1999 06:22:40 -0000	1.4
+++ serverboot/wiring.c	9 Aug 2003 12:04:21 -0000
@@ -75,6 +75,59 @@
 	    panic("wire_thread: %d", kr);
 }
 
+#ifdef OSFMACH
+void
+wire_all_memory()
+{
+  register kern_return_t kr;
+  vm_offset_t address;
+  vm_size_t size;
+  struct vm_region_basic_info info;
+  memory_object_name_t object;
+  mach_msg_type_number_t cnt = VM_REGION_BASIC_INFO_COUNT;
+
+  if (priv_host_port == MACH_PORT_NULL)
+    return;
+
+  /* iterate thru all regions, wiring */
+  address = 0;
+  while (
+	 (kr = vm_region (this_task, &address, &size, VM_REGION_BASIC_INFO,
+			  (vm_region_info_t) &info, &cnt, &object))
+	 == KERN_SUCCESS)
+    {
+      if (MACH_PORT_VALID (object))
+	(void) mach_port_deallocate (this_task, object);
+      if (info.protection != VM_PROT_NONE)
+	{
+	  /* The VM system cannot cope with a COW fault on another
+	     unrelated virtual copy happening later when we have
+	     wired down the original page.  So we must touch all our
+	     pages before wiring to make sure that only we will ever
+	     use them.  */
+	  void *page;
+	  if (!(info.protection & VM_PROT_WRITE))
+	    {
+	      kr = vm_protect(this_task, address, size,
+			      0, info.max_protection);
+	    }
+	  for (page = (void *) address;
+	       page < (void *) (address + size);
+	       page += vm_page_size)
+	    *(volatile int *) page = *(int *) page;
+
+	  wire_memory(address, size, info.protection);
+
+	  if (!(info.protection & VM_PROT_WRITE))
+	    {
+	      kr = vm_protect(this_task, address, size,
+			      0, info.protection);
+	    }
+	}
+      address += size;
+    }
+}
+#else
 void
 wire_all_memory()
 {
@@ -135,6 +188,7 @@
 	    address += size;
 	}
 }
+#endif  /* OSFMACH */
 
 /*
  * Alias for vm_allocate to return wired memory.

