On Tuesday 22 Nov 2005 09:47, Marco Gerards wrote:
> Timothy Baldwin <[EMAIL PROTECTED]> writes:

> > 2005-08-29  Timothy Baldwin <[EMAIL PROTECTED]>
> >         * boot/arm/RISC_OS/!Run,feb: New file.
>
> I would prefer another name and renaming when installing.  I wonder
> what other people think about that.

How should that be done within the framework of our build system?

> >         * Makefile.in (RMKFILES): Add arm-RISC_OS.rmk and common.rmk to
> > list.
>
> Wasn't common.rmk added already?

Out of date Changelog


> > +# For grub_RO.img.

Oops, wrong comment. The filename is "grub_RO,ff8".

> > +grub_RO_ff8_SOURCES = kern/arm/aif_header.S \
>
> What's RO_ff8?

The "_RO" is to distingush the RISC OS grub kernel, from, for example, a ARM 
IEEE1275 grub kernel.  "ff8" is the RISC OS filetype for an executable file.
I've changed this to lower case.

>
> > +#define SEEK_SET 0
> > +#define SEEK_END 2
>
> can you use a prefix here?  for example GRUB_RISC_OS_SEEK_SET.

Reasonable, however removing the prefix from the C library functions declared 
in that file would make the code clearer for the reasons below, make code in 
GRUB more portable and more consistent in style. We don't call open() 
grub_posix_open()!

Perhaps we could use the library headers from gccsdk at 
http://gccsdk.riscos.info/cgi-bin/cvsweb.cgi/gccsdk/libscl/ instead of 
writing our own. When I started work on the RISC OS port, those headers 
lacked a licence, now they have the BSD licence without the advertising 
clause.  But we would need to declare the exports separately.

> > +#define Cache_Control 0x280
>
> [...]
>
> > +#define Service_PreReset 0x45


> Can you please change this so it is according to the GCS?
> And please use a prefix.

That would only serve to obfuscate the code:
 - A prefix would suggest that GRUB implements these system calls.
 - It would be harder to find the documention.
 - Those are the standard system call names, and are universally used by RISC 
OS programs, therefore the common ones easily recognisable by RISC OS 
assembly language programmers. 

And technically the names in this file is outside the scope of the GCS, by 
virtue of only being included in RISC OS specific assembler.


> Have you considered using the GRUB memory allocation routines?  What
> are the advantages and disadvantages?

Since the RISC OS C Library is used, it's memory allocation routines have 
control of the memory in the application space. Not using the C library 
results in a large amount of hard to debug assembly using infrequently used, 
poorly documented, low-level interfaces.

> And some general remarks:
>
> The copyright years are not always updated to 2005, is this correct?

Some of it was written in 2004.

> Sometimes you mentioned copyright with your name.  Can that be
> changed?

Oversight corrected.

> Not all C comments are formatted correctly.  Always start a sentence with a
> capital letter and end with a `.'.  Put two spaces after a sentence.

I hope I've corrected these, but I'm not sure what counts as a sentence.

2005-08-29  Timothy Baldwin <[EMAIL PROTECTED]>
        * boot/arm/risc_os/!Run,feb: New file.
        * kern/arm/aif_header.lds: Likewise.
        * kern/arm/aif_header.S: Likewise.
        * kern/arm/dl.c: Likewise.
        * kern/arm/risc_os/init.c: Likewise.
        * kern/arm/risc_os/misc.c: Likewise.
        * kern/arm/risc_os/startup.S: Likewise.
        * normal/arm/setjmp.S: Likewise.
        * include/grub/arm/libgcc.h: Likewise.
        * include/grub/arm/risc_os/console.h: Likewise.
        * include/grub/arm/risc_os/misc.h: Likewise.
        * include/grub/arm/risc_os/swis.h: Likewise.
        * include/grub/arm/risc_os/time.h: Likewise.
        * include/grub/arm/setjmp.h: Likewise.
        * conf/arm-risc_os.rmk: Likewise.

        * include/grub/misc.h (grub_align): New macro.
        (memset): New prototype.

        * include/grub/powerpc/libgcc.h: (memset): Deleted.

        * Makefile.in (RMKFILES): Add arm-risc_os.rmk and common.rmk to list.

        * configure.ac: Add tests for ARM and -std=gnu99 gcc option.


-- 
Member AFFS, WYLUG, SWP (UK), UAF, RESPECT, StWC
No to software patents!    Victory to the iraqi resistance!
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/boot/arm/risc_os/!Run,feb grub2_risc_os/boot/arm/risc_os/!Run,feb
--- grub2/boot/arm/risc_os/!Run,feb	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/boot/arm/risc_os/!Run,feb	2005-11-24 23:07:03.000000000 +0000
@@ -0,0 +1,33 @@
+| !Run - start grub on RISC OS.
+
+| GRUB  --  GRand Unified Bootloader
+| Copyright (C) 2005  Free Software Foundation, Inc.
+|
+| This program is free software; you can redistribute it and/or modify
+| it under the terms of the GNU General Public License as published by
+| the Free Software Foundation; either version 2 of the License, or
+| (at your option) any later version.
+|
+| This program is distributed in the hope that it will be useful,
+| but WITHOUT ANY WARRANTY; without even the implied warranty of
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+| GNU General Public License for more details.
+|
+| You should have received a copy of the GNU General Public License
+| along with this program; if not, write to the Free Software
+| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+| Record this directory
+Set Grub$Dir <Obey$Dir>
+Set Alias$Grub Run |<Grub$Dir>
+
+| Set text window to full screen and use default colours.
+Echo <20><26><12>
+Pointer 0
+
+| Ensure we have enough memory
+Wimpslot 256K 256K
+
+| Start grub
+Run <Grub$Dir>.grub_ro %*0
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/conf/arm-risc_os.rmk grub2_risc_os/conf/arm-risc_os.rmk
--- grub2/conf/arm-risc_os.rmk	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/conf/arm-risc_os.rmk	2005-11-24 23:07:58.000000000 +0000
@@ -0,0 +1,64 @@
+# -*- makefile -*-
+
+COMMON_ASFLAGS = -nostdinc -fno-builtin -Wa,--gstabs
+COMMON_CFLAGS = -fno-builtin -ffixed-r10 -mapcs-frame -mpoke-function-name
+
+pkgdata_DATA = $(srcdir)/boot/arm/risc_os/!Run,feb
+
+# Images.
+pkgdata_IMAGES = grub_ro,ff8
+
+# For grub_r0.,ff8.
+grub_ro_ff8_SOURCES = kern/arm/aif_header.S \
+	kern/main.c kern/device.c kern/parser.c \
+	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
+	kern/misc.c  kern/loader.c kern/rescue.c kern/term.c \
+	kern/partition.c kern/env.c symlist.c \
+	kern/arm/dl.c kern/arm/risc_os/startup.S\
+	kern/arm/risc_os/init.c kern/arm/risc_os/misc.c \
+	term/arm/risc_os/console.c term/arm/risc_os/console-asm.S \
+	
+grub_ro_ff8_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
+	file.h fs.h kernel.h loader.h misc.h mm.h net.h partition.h \
+	pc_partition.h rescue.h symbol.h term.h types.h parser.h \
+	arm/libgcc.h \
+	arm/risc_os/misc.h  \
+	arm/risc_os/time.h
+	
+grub_ro_ff8_CFLAGS = $(COMMON_CFLAGS)
+grub_ro_ff8_ASFLAGS = $(COMMON_ASFLAGS)
+grub_ro_ff8_LDFLAGS = `$(CC) -print-libgcc-file-name` $(srcdir)/kern/arm/aif_header.lds -nostdlib -Wl,-N,-Ttext,8000
+
+MOSTLYCLEANFILES += symlist.c grub_ro_syms.lst
+DEFSYMFILES += grub_ro_syms.lst
+
+symlist.c: $(addprefix include/grub/,$(grub_ro_ff8_HEADERS)) gensymlist.sh
+	sh $(srcdir)/gensymlist.sh $(filter %.h,$^) > $@
+
+grub_ro_syms.lst: $(addprefix include/grub/,$(grub_ro_ff8_HEADERS)) genkernsyms.sh
+	sh $(srcdir)/genkernsyms.sh $(filter %h,$^) > $@
+
+
+
+# Utilities.
+noinst_UTILITIES = genmoddep
+
+
+# For genmoddep.
+genmoddep_SOURCES = util/genmoddep.c
+
+# Modules.
+pkgdata_MODULES =  normal.mod 
+# For normal.mod.
+
+normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c	\
+	normal/completion.c normal/context.c normal/execute.c 		\
+	normal/function.c normal/lexer.c normal/main.c normal/menu.c	\
+	normal/menu_entry.c normal/misc.c grub_script.tab.c 		\
+	normal/script.c normal/arm/setjmp.S
+normal_mod_CFLAGS = $(COMMON_CFLAGS)
+normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
+normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+
+include $(top_srcdir)/conf/common.mk
\ No newline at end of file
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/configure.ac grub2_risc_os/configure.ac
--- grub2/configure.ac	2005-11-08 18:39:52.000000000 +0000
+++ grub2_risc_os/configure.ac	2005-11-24 15:35:24.000000000 +0000
@@ -24,6 +24,7 @@ case "$host_cpu" in
   i[[3456]]86) host_cpu=i386 ;;
   x86_64) host_cpu=i386 amd64=1 ;;
   powerpc) ;;
+  arm) ;;
   sparc64) ;;
   *) AC_MSG_ERROR([unsupported CPU type]) ;;
 esac
@@ -31,6 +32,7 @@ esac
 case "$host_cpu"-"$host_vendor" in
   i386-*) host_vendor=pc ;;
   powerpc-*) host_vendor=ieee1275 ;;
+  arm-*) host_vendor=risc_os ;;
   sparc64-*) host_vendor=ieee1275 ;;
   *) AC_MSG_ERROR([unsupported machine type]) ;;
 esac
@@ -66,6 +68,23 @@ if test "x$default_CFLAGS" = xyes; then
     tmp_CFLAGS="$tmp_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
   fi
 
+  # C99.
+  AC_CACHE_CHECK([whether -std=gnu99 works], c99_flag, [
+    CFLAGS=-std=gnu99
+    AC_TRY_COMPILE(, , c99_flag=yes, c99_flag=no)
+  ])
+  if test "x$c99_flag" = xyes; then
+    tmp_CFLAGS="$tmp_CFLAGS -std=gnu99"
+  fi
+
+  AC_CACHE_CHECK([whether -fstd=gnu9x works], c9x_flag, [
+    CFLAGS=-fstd=gnu9x
+    AC_TRY_COMPILE(, , c9x_flag=yes, c9x_flag=no)
+  ])
+  if test "x$c9x_flag" = xyes; then
+    tmp_CFLAGS="$tmp_CFLAGS -fstd=gnu9x"
+  fi
+
   # Force no alignment to save space on i386.
   if test "x$host_cpu" = xi386; then
     AC_CACHE_CHECK([whether -falign-loops works], [falign_loop_flag], [
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/libgcc.h grub2_risc_os/include/grub/arm/libgcc.h
--- grub2/include/grub/arm/libgcc.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/libgcc.h	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,27 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+void EXPORT_FUNC (__clear_cache) (void *start, void *end);
+void EXPORT_FUNC (__udivsi3) (void);
+void EXPORT_FUNC (__umodsi3) (void);
+void EXPORT_FUNC (__divsi3) (void);
+void EXPORT_FUNC (__modsi3) (void);
+void EXPORT_FUNC (__ashldi3) (void);
+void EXPORT_FUNC (__lshrdi3) (void);
+void EXPORT_FUNC (__muldi3) (void);
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/risc_os/console.h grub2_risc_os/include/grub/arm/risc_os/console.h
--- grub2/include/grub/arm/risc_os/console.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/risc_os/console.h	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,43 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_CONSOLE_MACHINE_HEADER
+#define GRUB_CONSOLE_MACHINE_HEADER	1
+
+#ifndef ASM_FILE
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/term.h>
+
+/* These are global to share code between C and asm.  */
+void grub_console_real_putchar (int c);
+int EXPORT_FUNC (grub_console_checkkey) (void);
+int EXPORT_FUNC (grub_console_getkey) (void);
+grub_uint16_t grub_console_getxy (void);
+int grub_console_get_and_set_cursor_key_state (int);
+int grub_console_convert (int c);
+extern grub_uint16_t grub_console_getwh (void);
+
+/* Initialize the console system.  */
+void grub_console_initialise (void);
+int grub_console_in_taskwindow (void);
+#endif
+
+#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/risc_os/misc.h grub2_risc_os/include/grub/arm/risc_os/misc.h
--- grub2/include/grub/arm/risc_os/misc.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/risc_os/misc.h	2005-11-24 21:05:57.000000000 +0000
@@ -0,0 +1,80 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004,2005  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_MISC_MACHINE_HEADER
+#define GRUB_MISC_MACHINE_HEADER	1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/symbol.h>
+
+typedef struct grub_risc_os_error
+{
+  unsigned number;
+  char message[];
+} *grub_risc_os_error_t;
+
+/* Number of last RISC OS error passed to grub_risc_os_error_convert */
+extern unsigned EXPORT_VAR (grub_risc_os_errno);
+
+/* ISO C */
+typedef struct
+{
+  int pad[9];
+} grub_risc_os_FILE;
+
+#define GRUB_RISC_OS_SEEK_SET 0
+#define GRUB_RISC_OS_SEEK_END 2
+
+extern unsigned EXPORT_VAR (grub_risc_os_clib_errno);
+
+/* ISO C functions */
+grub_risc_os_FILE *grub_risc_os_fopen (const char *path, const char *mode);
+int grub_risc_os_fclose (grub_risc_os_FILE * fp);
+int grub_risc_os_fseek (grub_risc_os_FILE * stream, long offset, int whence);
+grub_ssize_t grub_risc_os_fread (void *ptr, grub_ssize_t size,
+				 grub_ssize_t nmemb,
+				 grub_risc_os_FILE * stream);
+long grub_risc_os_ftell (grub_risc_os_FILE * stream);
+void *grub_risc_os_malloc (grub_size_t size);
+void *grub_risc_os_realloc (void *ptr, grub_size_t size);
+void grub_risc_os_free (void *ptr);
+void *EXPORT_FUNC (grub_risc_os_system) (const char *);
+
+/* SharedCLibrary functions */
+grub_risc_os_error_t *EXPORT_FUNC (grub_risc_os_kernel_setenv) (const char
+								*name,
+								const char
+								*value);
+
+grub_err_t EXPORT_FUNC (grub_risc_os_error_convert) (grub_risc_os_error_t,
+						     grub_err_t);
+grub_err_t
+EXPORT_FUNC (grub_risc_os_error_convert_zero) (grub_risc_os_error_t,
+					       grub_err_t);
+grub_err_t EXPORT_FUNC (grub_risc_os_clib_error) (grub_err_t);
+grub_risc_os_error_t grub_risc_os_kernel_last_oserror (void);
+
+int EXPORT_FUNC (grub_risc_os_get_swi_number) (const char *);
+
+extern unsigned grub_risc_os_version;
+extern unsigned grub_risc_os_81C710_present;
+extern const char *grub_risc_os_dealer;
+
+#endif /* ! GRUB_MISC_MACHINE_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/risc_os/swis.h grub2_risc_os/include/grub/arm/risc_os/swis.h
--- grub2/include/grub/arm/risc_os/swis.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/risc_os/swis.h	2005-11-24 21:02:38.000000000 +0000
@@ -0,0 +1,83 @@
+/* swis.h - RISC OS SWI Numbers */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not write to the Free Software
+ *  Foundation Inc. 675 Mass Ave Cambridge MA 02139 USA.
+ */
+
+#ifndef GRUB_MACHINE_SWI_HEADER
+#define GRUB_MACHINE_SWI_HEADER 1
+
+#define X(x) ((x) | 0x20000)
+
+#define Cache_Control 0x280
+#define Cache_Flush 0x284
+#define ColourTrans_ReturnColourNumber 0x40744
+#define FileCore_DescribeDisc 0x40545
+#define FileCore_DiscOp 0x40540
+#define FileCore_DiscOp64 0x4054E
+#define FileCore_Drives 0x40542
+#define FileCore_MiscOp 0x40549
+#define FileCore_SectorOp 0x4054A
+#define Hourglass_Off 0x406C1
+#define Hourglass_On 0x406C0
+#define Hourglass_Smash 0x406C2
+#define OS_Args 0x09
+#define OS_BreakPt 0x17
+#define OS_Byte 0x06
+#define OS_Claim 0x1F
+#define OS_Release 0x20
+#define OS_ChangeDynamicArea 0x2A
+#define OS_ChangeEnvironment 0x40
+#define OS_CLI 0x05
+#define OS_ConvertHex8 0xD4
+#define OS_EnterOS 0x16
+#define OS_Exit 0x11
+#define OS_File 0x08
+#define OS_Find 0x0D
+#define OS_FSControl 0x29
+#define OS_GBPB 0x0C
+#define OS_GenerateError 0x2B
+#define OS_GetEnv 0x10
+#define OS_LeaveOS 0x7C
+#define OS_IntOff 0x14
+#define OS_Memory 0x68
+#define OS_Module 0x1E
+#define OS_ReadArgs 0x49
+#define OS_ReadC 0x04
+#define OS_ReadDynamicArea 0x5C
+#define OS_ReadMonotonicTime 0x42
+#define OS_ReadSysInfo 0x58
+#define OS_ReadUnsigned 0x21
+#define OS_ReadVduVariables 0x31
+#define OS_RemoveCursors 0x36
+#define OS_Reset 0x6A
+#define OS_ServiceCall 0x30
+#define OS_SWINumberFromString 0x39
+#define OS_SynchroniseCodeAreas 0x006E
+#define OS_Write0 0x02
+#define OS_WriteC 0x00
+#define OS_WriteI 0x100
+#define OS_WriteN 0x46
+#define OS_WriteS 0x01
+#define SharedCLibrary_LibInitAPCS_32 0x80683
+#define SharedCLibrary_LibInitAPCS_R 0x80681
+#define TaskWindow_TaskInfo 0x43380
+
+#define Service_PreReset 0x45
+#define GRUB_RISC_OS_ERROR_NO_SUCH_SWI 0x1E6
+
+#endif /* GRUB_MACHINE_SWI_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/risc_os/time.h grub2_risc_os/include/grub/arm/risc_os/time.h
--- grub2/include/grub/arm/risc_os/time.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/risc_os/time.h	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,33 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2003, 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef KERNEL_TIME_HEADER
+#define KERNEL_TIME_HEADER	1
+
+#ifdef GRUB_UTIL
+# include <time.h>
+# define GRUB_TICKS_PER_SECOND	CLOCKS_PER_SEC
+#else
+# define GRUB_TICKS_PER_SECOND	100
+#endif
+
+/* Return the real time in ticks.  */
+grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
+
+#endif /* ! KERNEL_TIME_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/setjmp.h grub2_risc_os/include/grub/arm/setjmp.h
--- grub2/include/grub/arm/setjmp.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/setjmp.h	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,25 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER	1
+
+typedef unsigned long grub_jmp_buf[10];
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/arm/types.h grub2_risc_os/include/grub/arm/types.h
--- grub2/include/grub/arm/types.h	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/include/grub/arm/types.h	2005-11-24 21:46:48.000000000 +0000
@@ -0,0 +1,35 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2004  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER	1
+
+/* The size of void *.  */
+#define GRUB_HOST_SIZEOF_VOID_P	4
+
+/* The size of long.  */
+#define GRUB_HOST_SIZEOF_LONG	4
+
+/* The size of a page.  */
+#define GRUB_HOST_PAGE_SIZE (0x400)
+
+/* ARM is little-endian.  (Or big-endian!! - but we don't support that yet.) */
+#undef GRUB_HOST_WORDS_BIGENDIAN
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/misc.h grub2_risc_os/include/grub/misc.h
--- grub2/include/grub/misc.h	2005-10-24 11:23:46.000000000 +0100
+++ grub2_risc_os/include/grub/misc.h	2005-11-24 15:35:24.000000000 +0000
@@ -29,6 +29,7 @@
 #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, __LINE__, condition, fmt, ## args);
 /* XXX: If grub_memmove is too slow, we must implement grub_memcpy.  */
 #define grub_memcpy(d,s,n)	grub_memmove ((d), (s), (n))
+#define grub_align(align, val) (((val) + ((align) - 1)) & ~((align) - 1))
 
 void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
 char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
@@ -40,6 +41,7 @@ char *EXPORT_FUNC(grub_strncat) (char *d
 /* Prototypes for aliases.  */
 void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
 void *EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
+void *EXPORT_FUNC(memset) (void *s, int c, grub_size_t n);
 
 int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
 int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/include/grub/powerpc/libgcc.h grub2_risc_os/include/grub/powerpc/libgcc.h
--- grub2/include/grub/powerpc/libgcc.h	2005-02-13 18:54:57.000000000 +0000
+++ grub2_risc_os/include/grub/powerpc/libgcc.h	2005-11-24 15:35:24.000000000 +0000
@@ -17,7 +17,6 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-void EXPORT_FUNC (memset) (void);
 void EXPORT_FUNC (__adddf3) (void);
 void EXPORT_FUNC (__addsf3) (void);
 void EXPORT_FUNC (__ashldi3) (void);
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/aif_header.lds grub2_risc_os/kern/arm/aif_header.lds
--- grub2/kern/arm/aif_header.lds	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/aif_header.lds	2005-11-24 18:00:55.000000000 +0000
@@ -0,0 +1,23 @@
+/* aif_header.lds - Calculate values for AIF header */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+grub_text_size = __data_start - _start;
+grub_data_size = _edata - __data_start;
+grub_bss_size = _end - _edata;
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/aif_header.S grub2_risc_os/kern/arm/aif_header.S
--- grub2/kern/arm/aif_header.S	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/aif_header.S	2005-11-24 18:00:55.000000000 +0000
@@ -0,0 +1,58 @@
+/* aif_header.S - AIF header */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C)  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  aword with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <grub/symbol.h>
+
+	.align
+	.global	_start
+_start:	nop
+	nop
+	bl	zeroinit
+	bl	grub_arm_startup
+lock:	b	lock	@ "Program exit instruction" (never reached)
+	.word	grub_text_size
+dsize:	.word	grub_data_size
+	.word	0	@ Debug data size
+zisize:	.word	grub_bss_size
+	.word	0	@ No Debug data
+	.word	_start
+	.word	0	@ Workspace for self-moving image (not used)
+	.word	32	@ Yes, we work in 32bit PC modes.
+dstart:	.word	__data_start
+	.word	0, 0 	@ Unused
+	nop		@ Initialise debugger (NOT!!)
+	
+zeroinit:
+	ldr	r0, dstart
+	ldr	r1, dsize
+	add	r0, r0, r1
+	ldr	r4, zisize
+	
+	@ Zero BSS area
+	mov	r1, #0	
+1:	str	r1, [r0], #4	
+	subs	r4, r4, #4
+	bcs	1b
+	mov	pc, lr
+	
+
+	.ltorg
+	. = _start + 128
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/dl.c grub2_risc_os/kern/arm/dl.c
--- grub2/kern/arm/dl.c	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/dl.c	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,114 @@
+/* dl.c - arch-dependent part of loadable module support */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2004,2005  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/dl.h>
+#include <grub/elf.h>
+#include <grub/misc.h>
+#include <grub/err.h>
+
+/* Check if EHDR is a valid ELF header.  */
+grub_err_t
+grub_arch_dl_check_header (void *ehdr)
+{
+  Elf32_Ehdr *e = ehdr;
+
+  /* Check the magic numbers.  */
+  if (e->e_ident[EI_CLASS] != ELFCLASS32
+      || e->e_ident[EI_DATA] != ELFDATA2LSB || e->e_machine != EM_ARM)
+    return grub_error (GRUB_ERR_BAD_MODULE,
+		       "invalid arch specific ELF magic");
+
+  return GRUB_ERR_NONE;
+}
+
+/* Relocate symbols.  */
+grub_err_t
+grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
+{
+  Elf32_Ehdr *e = ehdr;
+  Elf32_Shdr *s;
+  Elf32_Sym *symtab;
+  Elf32_Word entsize;
+  unsigned i;
+
+  /* Find a symbol table.  */
+  for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum; i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+    if (s->sh_type == SHT_SYMTAB)
+      break;
+
+  if (i == e->e_shnum)
+    return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found");
+
+  symtab = (Elf32_Sym *) ((char *) e + s->sh_offset);
+  entsize = s->sh_entsize;
+
+  for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum; i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+    if (s->sh_type == SHT_REL)
+      {
+	grub_dl_segment_t seg;
+
+	/* Find the target segment.  */
+	for (seg = mod->segment; seg; seg = seg->next)
+	  if (seg->section == s->sh_info)
+	    break;
+
+	if (seg)
+	  {
+	    Elf32_Rel *rel, *max;
+
+	    for (rel = (Elf32_Rel *) ((char *) e + s->sh_offset),
+		 max = rel + s->sh_size / s->sh_entsize; rel < max; rel++)
+	      {
+		Elf32_Word *addr;
+		Elf32_Sym *sym;
+
+		if (seg->size < rel->r_offset)
+		  return grub_error (GRUB_ERR_BAD_MODULE,
+				     "reloc offset is out of the segment");
+
+		addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
+		sym = (Elf32_Sym *) ((char *) symtab
+				     + entsize * ELF32_R_SYM (rel->r_info));
+
+		switch (ELF32_R_TYPE (rel->r_info))
+		  {
+		  case R_ARM_ABS32:
+		    *addr += sym->st_value;
+		    break;
+
+		  case R_ARM_PC24:
+		    *addr =
+		      (*addr & 0xFF000000) |
+		      ((*addr +
+			((sym->st_value -
+			  ((Elf32_Word) addr)) >> 2)) & 0x00FFFFFF);
+		    break;
+		  default:
+		    return grub_error (GRUB_ERR_BAD_MODULE,
+				       "unsupported reloc type");
+		  }
+	      }
+	  }
+      }
+
+  return GRUB_ERR_NONE;
+}
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/risc_os/init.c grub2_risc_os/kern/arm/risc_os/init.c
--- grub2/kern/arm/risc_os/init.c	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/risc_os/init.c	2005-11-24 18:00:55.000000000 +0000
@@ -0,0 +1,94 @@
+/* init.c - RISC OS Initialisation */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004,2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/kernel.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+#include <grub/machine/console.h>
+#include <grub/env.h>
+#include <grub/arm/risc_os/misc.h>
+
+extern const char *grub_risc_os_kernel_command_string (void);
+
+static unsigned grub_arm_linux_sysid;
+static const char *grub_machine_type_name;
+
+extern unsigned grub_arm_machine_serial_number[2];
+
+
+static inline void
+new_init (void)
+{
+  /* RISC OS version >= 3.5 */
+
+  if (grub_risc_os_dealer
+      && grub_strcmp (grub_risc_os_dealer, "Riscstation") == 0)
+    {
+      grub_arm_linux_sysid = 46;
+      grub_machine_type_name = "RiscStation";
+    }
+  else
+    {
+      grub_arm_linux_sysid = 1;
+      grub_machine_type_name = "RiscPC";
+    }
+
+  /* FIXME: Identify Bush Internet TV.  */
+  /* FIXME: Identify Iynoix PC.  */
+
+}
+
+static inline void
+old_init (void)
+{
+  /* RISC OS version < 3.5 */
+
+  if (grub_risc_os_81C710_present)
+    {
+      grub_arm_linux_sysid = 11;
+      grub_machine_type_name = "A5000";
+    }
+  else
+    {
+      grub_arm_linux_sysid = 10;
+      grub_machine_type_name = "Archimedes";
+    }
+}
+
+
+void
+grub_machine_init ()
+{
+  grub_console_initialise ();
+  grub_env_set ("prefix", "(host)/<Grub$Dir>");
+
+  if (grub_risc_os_version < 0xA5)
+    old_init ();
+  else
+    new_init ();
+
+  char buf[20];
+
+  grub_sprintf (buf, "%d", grub_arm_linux_sysid);
+  grub_env_set ("grub_arm_linux_sysid", buf);
+
+  grub_env_set ("grub_machine_type_name", grub_machine_type_name);
+
+}
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/risc_os/misc.c grub2_risc_os/kern/arm/risc_os/misc.c
--- grub2/kern/arm/risc_os/misc.c	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/risc_os/misc.c	2005-11-24 18:00:55.000000000 +0000
@@ -0,0 +1,110 @@
+/* misc.h - misc RISC OS bits */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004,2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not write to the Free Software
+ *  Foundation Inc. 675 Mass Ave Cambridge MA 02139 USA.
+ */
+
+#include <grub/arm/risc_os/misc.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+
+unsigned grub_risc_os_errno;
+
+grub_err_t
+grub_risc_os_error_convert (grub_risc_os_error_t err, grub_err_t n)
+{
+  grub_risc_os_errno = err->number;
+
+  switch (grub_risc_os_errno)
+    {
+    case 0xD6:
+      n = GRUB_ERR_FILE_NOT_FOUND;
+      break;
+    case 1052:
+      n = GRUB_ERR_BAD_FS;
+      break;
+    default:
+      break;
+    }
+  grub_dprintf ("error_convert", "RISC OS = 0x%x GRUB = %d\n", grub_risc_os_errno, n)
+  return grub_error (n, "%s", err->message);
+}
+
+unsigned
+grub_risc_os_error_convert_zero (struct grub_risc_os_error *err,
+				 grub_err_t err2)
+{
+  grub_risc_os_error_convert (err, err2);
+  return 0;
+}
+
+grub_err_t
+grub_risc_os_clib_error (grub_err_t err)
+{
+  return grub_risc_os_error_convert (grub_risc_os_kernel_last_oserror (),
+				     err);
+}
+
+void *
+grub_memalign (grub_size_t align, grub_size_t size)
+{
+  void **mem = grub_risc_os_malloc (size + align + sizeof (void *));
+  if (mem == 0)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
+      return 0;
+    }
+  void **result = (void **) grub_align (align, (unsigned) (mem + 1));
+  result[-1] = mem;
+  return result;
+}
+
+void *
+grub_malloc (grub_size_t size)
+{
+  void **result = grub_risc_os_malloc (size + sizeof (void *));
+  if (result == 0)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
+      return 0;
+    }
+  *result = result;
+  return result + 1;
+}
+
+void *
+grub_realloc (void *ptr, grub_size_t size)
+{
+  void **ptr2 = ptr;
+  void **result =
+    grub_risc_os_realloc (ptr2 ? ptr2[-1] : 0, size + sizeof (void *));
+  if (result == 0)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
+      return 0;
+    }
+  *result = result;
+  return result + 1;
+}
+
+void
+grub_free (void *ptr)
+{
+  void **ptr2 = ptr;
+  if (ptr2)
+    grub_risc_os_free (ptr2[-1]);
+}
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/kern/arm/risc_os/startup.S grub2_risc_os/kern/arm/risc_os/startup.S
--- grub2/kern/arm/risc_os/startup.S	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/kern/arm/risc_os/startup.S	2005-11-24 23:07:03.000000000 +0000
@@ -0,0 +1,314 @@
+/* startup.S - RISC OS Initialisation*/
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004,2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <grub/symbol.h>
+#include <grub/arm/risc_os/swis.h>
+
+
+	.bss
+	VARIABLE(grub_risc_os_81C710_present)
+	.space	4
+	VARIABLE(grub_arm_machine_serial_number)
+	.space	8
+	VARIABLE(grub_risc_os_version)
+	.space	4
+	VARIABLE(grub_risc_os_dealer)
+	.space	4
+	.text
+
+div0:	.word	0
+	.asciz	"Division by zero"
+c_str:	.asciz	"C"
+
+load_library:
+	@ FIXME: Versions? And do we need the floating point emulator?
+	.asciz	"RMEnsure SharedCLibrary 3.75 RMLoad System:Modules.Clib"
+	.align
+	
+	.global	grub_arm_startup
+grub_arm_startup:
+	swi	X(Hourglass_On)
+
+	adr	r0, load_library
+	swi	OS_CLI
+
+	ldr	r9, =grub_risc_os_81C710_present
+	mov	r0, #129
+	mov	r1, #0
+	mov	r2, #255
+	swi	OS_Byte
+	str	r1, [r9, #12]
+	cmp	r1, #0xA3
+	blo	1f @ Avoid RISC OS 2 OS_ReadSysInfo bug
+	
+	mov	r0, #9
+	mov	r1, #3
+	swi	X(OS_ReadSysInfo)
+	strvc	r0, [r9, #16]
+	
+	mov	r0, #2
+	swi	X(OS_ReadSysInfo)
+	stmvcia	r9, {r1, r3, r4}
+		
+1:	swi	OS_GetEnv
+	mov	r2, r1		@ r2 = End of heap
+	adr	r0, stubs
+	ldr	r1, =_end	@ r1 = Start of heap
+	mov	r3, #-1		@ Docs say so...
+	movs	r4, #0		@ Likewise
+	mov	r5, #-1		@ Likewise
+	mov	r6, #64 << 16	@ 64K stack
+	teq	pc, pc
+	orreq	r6, r6, #1	@ What is this for? (copied from gccsdk)
+	swi	X(SharedCLibrary_LibInitAPCS_32)
+	bvc	1f		@ Branch if no error
+	
+	@ If error was "SWI value out of range for module SharedCLibrary"
+	@ and we are in 26-bit PC mode try APCS R, otherwise raise error.
+	teq	pc, pc
+	swieq	OS_GenerateError
+	ldr	r14, [r0]
+	ldr	r13, =0x800E85
+	teq	r14, r13
+	swine	OS_GenerateError
+	adr	r0, stubs
+	swi	SharedCLibrary_LibInitAPCS_R
+1:	mov	r4, r0
+	adr	r0, kernel_init_block
+	mov	r3, #0
+	b	grub_risc_os_kernel_init
+	
+stubs:	.word	1
+	.word	kernel_vectors
+	.word	kernel_vectors_end
+	.word	kernel_statics
+	.word	kernel_statics_end
+	.word	2
+	.word	clib_vectors
+	.word	clib_vectors_end
+	.word	clib_statics
+	.word	clib_statics_end
+	.word	-1
+	
+	.bss
+kernel_vectors:
+	.space	48 * 4
+kernel_vectors_end:
+clib_vectors:
+	.space	183 * 4
+clib_vectors_end:
+
+kernel_statics:
+	.space	0x31C
+kernel_statics_end:
+clib_statics:
+	.space	0xB48
+clib_statics_end:
+
+	.macro	kernel, label, entry
+	.global	grub_risc_os_kernel_\label
+	grub_risc_os_kernel_\label = kernel_vectors + \entry * 4
+	.endm
+	
+	.macro	clib, label, entry
+	.global	grub_risc_os_\label
+	grub_risc_os_\label = clib_vectors + \entry * 4
+	.endm
+	
+	kallocExtendsWS = kernel_statics + 0x115
+	
+	.global grub_risc_os_clib_errno
+	grub_risc_os_clib_errno = clib_statics
+	
+	kernel	init, 0
+	kernel	command_string, 7
+	kernel	system, 22
+	kernel	last_oserror, 21
+	kernel	setenv, 24
+	
+	clib	malloc, 68
+	clib	free, 67
+	clib	realloc, 69
+	clib	system, 74
+	clib	atexit, 71
+	clib	exit, 72
+	clib	_clib_initialise, 20
+	clib	_clib_main, 18
+	clib	_backtrace, 21
+	
+	clib	fopen, 87
+	clib	fclose, 85
+	clib	fread, 114
+	clib	fseek, 117
+	clib	fwrite, 115
+	clib	ftell, 119
+	
+	clib	TrapHandler, 0
+	clib	UncaughtTrapHandler, 1
+	clib	EventHandler, 2
+	clib	UnhandledEventHandler, 3
+	
+	.text
+	
+	
+	.global	system
+	system = grub_risc_os_system
+	
+kernel_init_block:
+	.word	0x8000, rts_block, rts_block_end
+
+rts_block:
+	.word	rts_block_end - rts_block
+	.word	0x8000, 0x7FFFFFFC, c_str, c_init, 0
+	.word	grub_risc_os_TrapHandler
+	.word	grub_risc_os_UncaughtTrapHandler
+	.word	grub_risc_os_EventHandler
+	.word	grub_risc_os_UnhandledEventHandler
+rts_block_end:
+	
+
+	
+c_init:	str	lr, [sp, #-4]!
+	ldr	a1, =kallocExtendsWS
+	mov	a2, #1
+	strb	a2, [a1]
+	bl	grub_risc_os__clib_initialise
+	adr	a1, c_run
+	teq	a1, a1
+	teq	pc, pc
+	ldmnefd	sp!, {pc}^
+	ldr	pc, [sp], #4
+	
+c_run:	adr	a1, atexit_wrapper
+	bl	grub_risc_os_atexit
+	mov	a1, #17
+	bl	grub_risc_os_set_escape_char
+	bl	grub_risc_os_kernel_command_string
+	ldr	a2, =grub_main
+	bl	grub_risc_os__clib_main
+FUNCTION(grub_stop)
+	mov	a1, #0
+	b	grub_risc_os_exit	
+
+atexit_wrapper:
+	str	lr, [sp, #-4]!
+	bl	grub_machine_fini
+	mov	a1, #27
+	bl	grub_risc_os_set_escape_char
+	swi	X(Hourglass_Off)
+	teq	a1, a1
+	teq	pc, pc
+	ldmnefd	sp!, {pc}^
+	ldr	pc, [sp], #4
+
+	.global	__div0	
+__div0:	adr	r0, div0
+	swi	OS_GenerateError
+	
+
+FUNCTION(grub_arch_modules_addr)
+	mov	a1, #0x8000
+FUNCTION(grub_mm_init_region)
+FUNCTION(grub_machine_fini)
+	mov	pc, lr
+
+FUNCTION(grub_risc_os_set_escape_char)
+	mov	r1, r0
+	mov	r2, #0
+	mov	r0, #220
+	swi	OS_Byte
+	mov	pc, lr
+	
+FUNCTION(grub_get_rtc)
+	swi	OS_ReadMonotonicTime
+	mov	pc, lr
+	
+	
+	.global	__clear_cache
+__clear_cache:
+	stmfd	sp!, {r0-r2, lr}
+	mov	r2, r1
+	mov	r1, r0
+	mov	r0, #1
+	swi	X(OS_SynchroniseCodeAreas)
+	ldmfd	sp!, {r0-r2, pc}^
+
+FUNCTION(grub_arch_sync_caches)
+	add	r2, r1, r0
+	mov	r1, r0
+	mov	r0, #0
+	swi	X(OS_SynchroniseCodeAreas)
+	mov	pc, lr
+
+rc5pc_off:
+	.asciz	"%rc5pc off"
+	.align
+
+FUNCTION(grub_reboot)
+	adr	r0, rc5pc_off
+	swi	X(OS_CLI)
+	swi	OS_EnterOS
+	mov	r0, #23 @ Unmount filesystems
+	swi	OS_FSControl
+	swi	X(OS_Reset)	
+1:	bvc	1b
+	ldr	r1, [r0]
+	eor	r1, r1, #GRUB_RISC_OS_ERROR_NO_SUCH_SWI & 0xff00
+	teq	r1, #GRUB_RISC_OS_ERROR_NO_SUCH_SWI & 0x00ff
+	swine	OS_GenerateError
+	
+	@ If above call failed, we are running on an Archimedies.
+	mov	r0, #200
+	mov	r1, #2
+	swi	OS_Byte		@ Set Full Reset
+	teqp	pc, #0x08000003	@ SVC Mode with IRQ disabled.
+	mov	r1, #Service_PreReset
+	swi	X(OS_ServiceCall)
+1:	bvs	1b
+	teqp	pc, #0x0C000003	@ SVC Mode with interrupts disabled.
+	
+	@ Copy word from start of ROM to address 0, then execute it.
+	mov	r0, #0x03800000
+	ldr	r1, [r0]
+	str	r1, [r0, -r0]
+	mov	pc, #0
+	
+	
+FUNCTION(grub_risc_os_get_swi_number)
+	mov	r1, a1
+	swi	X(OS_SWINumberFromString)
+	movvs	a1, #0
+	mov	pc, lr
+
+FUNCTION(grub_risc_os_cli)
+	@ May be called in SVC mode.
+	mov	ip, lr
+	swi	X(OS_CLI)
+	mov	pc, ip
+
+	.data
+VARIABLE(grub_end_addr)
+	.word	_end
+
+	.bss	
+VARIABLE(grub_total_module_size)
+	.space	4
+
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/Makefile.in grub2_risc_os/Makefile.in
--- grub2/Makefile.in	2005-11-24 15:32:57.000000000 +0000
+++ grub2_risc_os/Makefile.in	2005-11-24 15:35:24.000000000 +0000
@@ -72,7 +72,7 @@ LIBLZO = @LIBLZO@
 ### General variables.
 
 RMKFILES = $(addprefix conf/,common.rmk i386-pc.rmk powerpc-ieee1275.rmk \
-	sparc64-ieee1275.rmk)
+	sparc64-ieee1275.rmk arm-risc_os.rmk)
 MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES))
 
 DATA = $(pkgdata_IMAGES) $(pkgdata_MODULES) $(pkgdata_PROGRAMS) \
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/normal/arm/setjmp.S grub2_risc_os/normal/arm/setjmp.S
--- grub2/normal/arm/setjmp.S	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/normal/arm/setjmp.S	2005-11-24 15:35:24.000000000 +0000
@@ -0,0 +1,33 @@
+/* setjmp.S - setjmp and longjmp */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  aword with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <grub/symbol.h>
+ 
+FUNCTION(grub_setjmp)
+	stmia	a1, {v1-v6, sl, fp, sp, lr}
+	mov	a1, #0
+	mov	pc, lr
+	
+FUNCTION(grub_longjmp)
+	ldmia	a1, {v1-v6, sl, fp, sp, lr}
+	movs	a1, a2
+	moveq	a1, #1
+	mov	pc, lr
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/term/arm/risc_os/console-asm.S grub2_risc_os/term/arm/risc_os/console-asm.S
--- grub2/term/arm/risc_os/console-asm.S	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/term/arm/risc_os/console-asm.S	2005-11-24 21:02:38.000000000 +0000
@@ -0,0 +1,84 @@
+/* console-asm.S - RISC OS Console */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004,2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <grub/symbol.h>
+#include <grub/arm/risc_os/swis.h>
+
+	.align
+
+FUNCTION(grub_console_real_putchar)
+	swi	OS_WriteC
+	mov	pc, lr
+
+FUNCTION(grub_console_getxy)
+	mov	r0, #165
+	swi	OS_Byte
+	orr	r0, r2, r1, lsl #8
+	mov	pc, lr
+
+FUNCTION(grub_console_getkey)
+	swi	X(Hourglass_Smash)
+	swi	OS_ReadC
+	mov	r1, r0
+	swi	X(Hourglass_On)
+	mov	r0, r1
+	b	grub_console_convert
+
+FUNCTION(grub_console_checkkey)
+	swi	X(Hourglass_Smash)
+	mov	r0, #129	@ Read key with time limit
+	mov	r1, #0		@ Timeout low byte
+	mov	r2, #0		@ Timeout high byte ( < 0x80 )
+	swi	OS_Byte
+	teq	r2, #0		@ r2 = 0 if key read
+	movne	r1, #-1		@ r1 = key if read
+	swi	X(Hourglass_On)
+	mov	r0, r1
+	b	grub_console_convert
+
+FUNCTION(grub_console_get_and_set_cursor_key_state)
+	mov	r1, a1
+	mov	r0, #4
+	swi	OS_Byte
+	mov	a1, r1
+	mov	pc, lr
+
+FUNCTION(grub_console_in_taskwindow)
+	mov	r0, #0
+	swi	X(TaskWindow_TaskInfo)
+	movvs	r0, #0
+	mov	pc, lr
+
+FUNCTION(grub_console_getwh)
+	sub	sp, sp, #20
+	adr	r0, vdu_variables
+	mov	r1, sp
+	swi	OS_ReadVduVariables
+	ldmia	sp!, {a1-a4, ip}
+	sub	a1, a3, a1 @ width  = right - left
+	add	a1, a1, #1 @          + 1
+	sub	a2, a2, a4 @ height = bottom - top
+	add	a2, a2, #1 @          + 1
+	orr	a1, a2, a1, lsl #8 @ result = (width << 8) | height
+	mov	pc, lr
+
+vdu_variables:
+	.word	0x84, 0x85, 0x86, 0x87, -1
diff -purN -x '*.mk' -x '*~' -x autom4te.cache -x configure -x '.#*' -x '*.orig' -x '*.rej' -x CVS grub2/term/arm/risc_os/console.c grub2_risc_os/term/arm/risc_os/console.c
--- grub2/term/arm/risc_os/console.c	1970-01-01 01:00:00.000000000 +0100
+++ grub2_risc_os/term/arm/risc_os/console.c	2005-11-24 22:56:52.000000000 +0000
@@ -0,0 +1,191 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2003,2004,2005  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/arm/risc_os/console.h>
+#include <grub/term.h>
+#include <grub/types.h>
+
+
+static void
+grub_console_putchar (grub_uint32_t c)
+{
+  /* Map some unicode characters to the RISC OS font, if possible.  */
+  switch (c)
+    {
+    case GRUB_TERM_DISP_LEFT:
+      c = 0x88;
+      break;
+    case GRUB_TERM_DISP_RIGHT:
+      c = 0x89;
+      break;
+    case GRUB_TERM_DISP_DOWN:
+      c = 0x8a;
+      break;
+    case GRUB_TERM_DISP_UP:
+      c = 0x8b;
+      break;
+    case GRUB_TERM_DISP_HLINE:
+      c = '-';
+      break;
+    case GRUB_TERM_DISP_VLINE:
+      c = '|';
+      break;
+    case GRUB_TERM_DISP_UL:	/* upper-left corner */
+      c = '+';
+      break;
+    case GRUB_TERM_DISP_UR:	/* upper-right corner */
+      c = '+';
+      break;
+    case GRUB_TERM_DISP_LL:	/* lower-left corner */
+      c = '+';
+      break;
+    case GRUB_TERM_DISP_LR:	/* lower-right corner */
+      c = '+';
+      break;
+
+    default:
+      //c = '?';
+      break;
+
+    }
+  if (c > 0x100)
+    c = '?';
+
+  grub_console_real_putchar (c);
+}
+
+static void
+grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y)
+{
+  grub_console_real_putchar (31);
+  grub_console_real_putchar (x);
+  grub_console_real_putchar (y);
+}
+
+static void
+grub_console_cls (void)
+{
+  grub_console_real_putchar (12);
+}
+
+static void
+nulls (void)
+{
+  for (int i = 8; i != 0; --i)
+    {
+      grub_console_real_putchar (0);
+    }
+}
+
+static void
+grub_console_setcursor (int on)
+{
+  grub_console_real_putchar (23);
+  grub_console_real_putchar (1);
+  grub_console_real_putchar (on);
+  nulls ();
+}
+
+static grub_term_color_state colourstate;
+
+static void
+grub_console_setcolourstate (grub_term_color_state state)
+{
+  state &= 2;
+  if (colourstate == state)
+    return;
+  colourstate = state;
+  grub_console_real_putchar (23);
+  grub_console_real_putchar (17);
+  grub_console_real_putchar (5);
+  nulls ();
+}
+
+static int old_cursor_key_state;
+
+static grub_err_t
+grub_console_init (void)
+{
+  old_cursor_key_state = grub_console_get_and_set_cursor_key_state (1);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_console_fini (void)
+{
+  grub_console_get_and_set_cursor_key_state (old_cursor_key_state);
+  return GRUB_ERR_NONE;
+}
+
+int
+grub_console_convert (int c)
+{
+  switch (c)
+    {
+    case 136:
+      c = 2;
+      break;
+    case 137:
+      c = 6;
+      break;
+    case 138:
+      c = 14;
+      break;
+    case 139:
+      c = 16;
+      break;
+    }
+  return c;
+}
+
+static grub_ssize_t
+grub_console_getcharwidth (grub_uint32_t c)
+{
+  (void) c;
+  return 1;
+}
+
+static struct grub_term grub_console_term =
+{
+  .name = "console",
+  .init = grub_console_init,
+  .fini = grub_console_fini,
+  .putchar = grub_console_putchar,
+  .checkkey = grub_console_checkkey,
+  .getkey = grub_console_getkey,
+  .getwh = grub_console_getwh,
+  .getxy = grub_console_getxy,
+  .gotoxy = grub_console_gotoxy,
+  .cls = grub_console_cls,
+  .setcolorstate = grub_console_setcolourstate,
+  .setcolor = 0,
+  .setcursor = grub_console_setcursor,
+  .flags = 0,
+  .next = 0,
+  .getcharwidth = grub_console_getcharwidth,
+};
+
+void
+grub_console_initialise (void)
+{
+  if (grub_console_in_taskwindow ())
+    grub_console_term.flags = GRUB_TERM_DUMB;
+  grub_term_register (&grub_console_term);
+  grub_term_set_current (&grub_console_term);
+}

Attachment: pgpvcUvQZko25.pgp
Description: PGP signature

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to