diff -ruN linux-2.6.21.1.orig/arch/mips/Kconfig linux-2.6.21.1/arch/mips/Kconfig
--- linux-2.6.21.1.orig/arch/mips/Kconfig	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/Kconfig	2007-07-19 22:04:50.000000000 +0200
@@ -552,6 +552,14 @@
 	  simulate actual MIPS hardware platforms.  More information on Qemu
 	  can be found at http://www.linux-mips.org/wiki/Qemu.
 
+config SONY_PS2
+	bool "Sony Playstation 2"
+	select SYS_HAS_CPU_R4X00
+	select SYS_SUPPORTS_64BIT_KERNEL
+	select SYS_SUPPORTS_LITTLE_ENDIAN
+	select SYS_HAS_EARLY_PRINTK
+	select IRQ_CPU
+
 config MARKEINS
 	bool "Support for NEC EMMA2RH Mark-eins"
 	select DMA_NONCOHERENT
@@ -1274,6 +1282,9 @@
 	help
 	  MIPS Technologies R5000-series processors other than the Nevada.
 
+config CPU_R5900
+	bool "R5900"
+
 config CPU_R5432
 	bool "R5432"
 	depends on SYS_HAS_CPU_R5432
diff -ruN linux-2.6.21.1.orig/arch/mips/kernel/cpu-probe.c linux-2.6.21.1/arch/mips/kernel/cpu-probe.c
--- linux-2.6.21.1.orig/arch/mips/kernel/cpu-probe.c	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/kernel/cpu-probe.c	2007-06-03 23:37:30.000000000 +0200
@@ -306,6 +306,12 @@
 			     MIPS_CPU_LLSC;
 		c->tlbsize = 48;
 		break;
+	case PRID_IMP_R5900:
+		c->cputype = CPU_R4600;
+		c->isa_level = MIPS_CPU_ISA_III;
+		c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR;
+		c->tlbsize = 48;
+		break;
 	#if 0
  	case PRID_IMP_R4650:
 		/*
diff -ruN linux-2.6.21.1.orig/arch/mips/kernel/head.S linux-2.6.21.1/arch/mips/kernel/head.S
--- linux-2.6.21.1.orig/arch/mips/kernel/head.S	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/kernel/head.S	2007-06-01 21:23:19.000000000 +0200
@@ -149,7 +149,6 @@
 	__INIT
 
 NESTED(kernel_entry, 16, sp)			# kernel entry point
-
 	kernel_entry_setup			# cpu specific setup
 
 	setup_c0_status_pri
@@ -187,7 +186,8 @@
 	LONG_S		a2, fw_arg2
 	LONG_S		a3, fw_arg3
 
-	MTC0		zero, CP0_CONTEXT	# clear context register
+#	MTC0		zero, CP0_CONTEXT	# clear context register
+	mtc0		zero, CP0_CONTEXT	# clear context register
 	PTR_LA		$28, init_thread_union
 	PTR_LI		sp, _THREAD_SIZE - 32
 	PTR_ADDU	sp, $28
diff -ruN linux-2.6.21.1.orig/arch/mips/kernel/setup.c linux-2.6.21.1/arch/mips/kernel/setup.c
--- linux-2.6.21.1.orig/arch/mips/kernel/setup.c	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/kernel/setup.c	2007-06-07 13:40:14.000000000 +0200
@@ -280,8 +280,7 @@
 	 * not selected. Once that done we can determine the low bound
 	 * of usable memory.
 	 */
-	reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));
-
+	reserved_end = max(init_initrd(), PFN_UP((unsigned int)__pa_symbol(&_end)));
 	/*
 	 * max_low_pfn is not a number of pages. The number of pages
 	 * of the system is given by 'max_low_pfn - min_low_pfn'.
@@ -297,7 +296,6 @@
 
 		if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
 			continue;
-
 		start = PFN_UP(boot_mem_map.map[i].addr);
 		end = PFN_DOWN(boot_mem_map.map[i].addr
 				+ boot_mem_map.map[i].size);
@@ -312,7 +310,7 @@
 			continue;
 		mapstart = max(reserved_end, start);
 	}
-
+	printk("%lx %lx\n",max_low_pfn,min_low_pfn);
 	if (min_low_pfn >= max_low_pfn)
 		panic("Incorrect memory mapping !!!");
 	if (min_low_pfn > ARCH_PFN_OFFSET) {
@@ -325,8 +323,8 @@
 		       "%lu free pages won't be used\n",
 		       ARCH_PFN_OFFSET - min_low_pfn);
 	}
+	
 	min_low_pfn = ARCH_PFN_OFFSET;
-
 	/*
 	 * Determine low and high memory ranges
 	 */
@@ -343,6 +341,7 @@
 	 */
 	bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
 					 min_low_pfn, max_low_pfn);
+	printk("bbb: %lx,%lx,%lx\n",mapstart,min_low_pfn,max_low_pfn);
 	/*
 	 * Register fully available low RAM pages with the bootmem allocator.
 	 */
@@ -385,7 +384,6 @@
 	 * Reserve the bootmap memory.
 	 */
 	reserve_bootmem(PFN_PHYS(mapstart), bootmap_size);
-
 	/*
 	 * Reserve initrd memory if needed.
 	 */
diff -ruN linux-2.6.21.1.orig/arch/mips/kernel/traps.c linux-2.6.21.1/arch/mips/kernel/traps.c
--- linux-2.6.21.1.orig/arch/mips/kernel/traps.c	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/kernel/traps.c	2007-06-07 17:13:15.000000000 +0200
@@ -1398,13 +1398,12 @@
 /* Install uncached CPU exception handler */
 void __init set_uncached_handler (unsigned long offset, void *addr, unsigned long size)
 {
-#ifdef CONFIG_32BIT
+/*#ifdef CONFIG_32BIT*/
 	unsigned long uncached_ebase = KSEG1ADDR(ebase);
-#endif
+/*#endif
 #ifdef CONFIG_64BIT
 	unsigned long uncached_ebase = TO_UNCAC(ebase);
-#endif
-
+#endif*/
 	memcpy((void *)(uncached_ebase + offset), addr, size);
 }
 
@@ -1517,7 +1516,6 @@
 		//set_except_vector(15, handle_ndc);
 	}
 
-
 	if (board_nmi_handler_setup)
 		board_nmi_handler_setup();
 
diff -ruN linux-2.6.21.1.orig/arch/mips/kernel/vmlinux.lds.S linux-2.6.21.1/arch/mips/kernel/vmlinux.lds.S
--- linux-2.6.21.1.orig/arch/mips/kernel/vmlinux.lds.S	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/kernel/vmlinux.lds.S	2007-06-01 13:06:46.000000000 +0200
@@ -5,6 +5,7 @@
 #define mips mips
 OUTPUT_ARCH(mips)
 ENTRY(kernel_entry)
+/*ENTRY(graphik)*/
 jiffies = JIFFIES;
 SECTIONS
 {
diff -ruN linux-2.6.21.1.orig/arch/mips/Makefile linux-2.6.21.1/arch/mips/Makefile
--- linux-2.6.21.1.orig/arch/mips/Makefile	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/Makefile	2007-06-04 15:26:57.000000000 +0200
@@ -127,6 +127,7 @@
 cflags-$(CONFIG_CPU_MIPS64_R2)	+= $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64) \
 			-Wa,-mips64r2 -Wa,--trap
 cflags-$(CONFIG_CPU_R5000)	+= -march=r5000 -Wa,--trap
+cflags-$(CONFIG_CPU_R5900)	+= -march=r5900 -Wa,--trap
 cflags-$(CONFIG_CPU_R5432)	+= $(call cc-option,-march=r5400,-march=r5000) \
 			-Wa,--trap
 cflags-$(CONFIG_CPU_NEVADA)	+= $(call cc-option,-march=rm5200,-march=r5000) \
@@ -374,6 +375,12 @@
 load-$(CONFIG_QEMU)		+= 0xffffffff80010000
 
 #
+# Playstation 2
+#
+core-$(CONFIG_SONY_PS2)		+= arch/mips/ps2/
+load-$(CONFIG_SONY_PS2)		+= 0x00100000
+
+#
 # Momentum Ocelot-3
 #
 core-$(CONFIG_MOMENCO_OCELOT_3) 	+= arch/mips/momentum/ocelot_3/
diff -ruN linux-2.6.21.1.orig/arch/mips/mm/c-r4k.c linux-2.6.21.1/arch/mips/mm/c-r4k.c
--- linux-2.6.21.1.orig/arch/mips/mm/c-r4k.c	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/mm/c-r4k.c	2007-06-07 16:27:42.000000000 +0200
@@ -734,6 +734,20 @@
 		c->options |= MIPS_CPU_CACHE_CDEX_P;
 		break;
 
+	case CPU_R5900:
+		icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
+		c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
+		c->icache.ways = 2;
+		c->icache.waybit= 0;
+
+		dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
+		c->dcache.linesz = 16 << ((config & CONF_DB) >> 5);
+		c->dcache.ways = 2;
+		c->dcache.waybit = 0;
+
+		c->options |= MIPS_CPU_CACHE_CDEX_P;
+		break;
+
 	case CPU_TX49XX:
 		icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
 		c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
diff -ruN linux-2.6.21.1.orig/arch/mips/mm/init.c linux-2.6.21.1/arch/mips/mm/init.c
--- linux-2.6.21.1.orig/arch/mips/mm/init.c	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/arch/mips/mm/init.c	2007-06-07 13:38:15.000000000 +0200
@@ -343,7 +343,6 @@
 	unsigned long zholes_size[MAX_NR_ZONES] = { 0, };
 	unsigned long i, j, pfn;
 #endif
-
 	pagetable_init();
 
 #ifdef CONFIG_HIGHMEM
@@ -395,7 +394,6 @@
 {
 	unsigned long codesize, reservedpages, datasize, initsize;
 	unsigned long tmp, ram;
-
 #ifdef CONFIG_HIGHMEM
 #ifdef CONFIG_DISCONTIGMEM
 #error "CONFIG_HIGHMEM and CONFIG_DISCONTIGMEM dont work together yet"
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/console.c linux-2.6.21.1/arch/mips/ps2/console.c
--- linux-2.6.21.1.orig/arch/mips/ps2/console.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/console.c	2007-06-07 23:39:21.000000000 +0200
@@ -0,0 +1,116 @@
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/kd.h>
+#include <linux/console_struct.h>
+
+static void ps2_con_startup()
+{
+//	graphik("alive-console-startup");
+}
+
+static void ps2_con_init(struct vc_data * vc, int i)
+{
+//	graphik("alive-con_init");
+	vc->vc_cols=25;
+	vc->vc_rows=80;
+}
+
+static void ps2_con_deinit()
+{
+	graphik("alive-dummy1");
+}
+static void ps2_con_clear()
+{
+//	graphik("alive-dummy2");
+}
+static void ps2_con_putc(struct vc_data *vc, int c, int ypos, int xpos)
+{
+	char buf[10];
+	snprintf(buf,"dum %x\n",10,c);
+	graphik(buf);
+	prom_putchar(c);
+	graphik("alive-dummy3");
+}
+static void ps2_con_putcs(struct vc_data * vc, unsigned short * s, int c, int ypos, int xpos)
+{
+	char buf[10];
+	snprintf(buf,"%x\n",10,s[0]);
+	graphik(buf);
+	int i=0;
+	for(i=0;i<c;i++)
+	{
+		if((s[i]&0xff)=='C')
+			graphik("forseC");
+		prom_putchar(s[i]);
+	}
+}
+static void ps2_con_cursor()
+{
+//	graphik("alive-dummy5");
+}
+static void ps2_con_scroll()
+{
+	graphik("alive-dummy6");
+}
+static void ps2_con_bmove()
+{
+	graphik("alive-dummy7");
+}
+static int ps2_con_switch(struct vc_data* vc)
+{
+	return 0;
+//	graphik("alive-dummy8");
+}
+static void ps2_con_blank()
+{
+	graphik("alive-dummy9");
+}
+static void ps2_con_font_set()
+{
+	graphik("alive-dummy10");
+}
+static void ps2_con_font_get()
+{
+	graphik("alive-dummy11");
+}
+static void ps2_con_resize()
+{
+	graphik("alive-dummy12");
+}
+static void ps2_con_set_palette()
+{
+//	graphik("alive-dummy13");
+}
+static void ps2_con_scrolldelta()
+{
+	graphik("alive-dummy14");
+}
+static void ps2_con_set_origin(struct vc_data * vc)
+{
+//	graphik("alive-dummy");
+}
+static void ps2_con_save_screen()
+{
+//\	graphik("alive-dummy15");
+}
+
+const struct consw ps2_con = {
+        .con_startup = ps2_con_startup,
+        .con_init = ps2_con_init,
+        .con_deinit = ps2_con_deinit,
+        .con_clear = ps2_con_clear,
+        .con_putc = ps2_con_putc,
+        .con_putcs = ps2_con_putcs,
+        .con_cursor = ps2_con_cursor,
+        .con_scroll = ps2_con_scroll,
+        .con_bmove = ps2_con_bmove,
+        .con_switch = ps2_con_switch,
+        .con_blank = ps2_con_blank,
+        .con_font_set = ps2_con_font_set,
+        .con_font_get = ps2_con_font_get,
+        .con_resize = ps2_con_resize,
+        .con_set_palette = ps2_con_set_palette,
+        .con_scrolldelta = ps2_con_scrolldelta,
+        .con_set_origin = ps2_con_set_origin,
+        .con_save_screen = ps2_con_save_screen,
+};
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/defines.h linux-2.6.21.1/arch/mips/ps2/defines.h
--- linux-2.6.21.1.orig/arch/mips/ps2/defines.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/defines.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,20 @@
+//---------------------------------------------------------------------------
+// File:	defines.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Commonly used data-type definitions.
+//---------------------------------------------------------------------------
+#ifndef DEFINES_H
+#define DEFINES_H
+
+typedef char	int8;
+typedef short	int16;
+typedef int		int32;
+
+typedef unsigned char	uint8;
+typedef unsigned short	uint16;
+typedef unsigned int	uint32;
+
+typedef unsigned long long	uint64;
+typedef long long		int64;
+
+#endif // DEFINES_H
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/dma.h linux-2.6.21.1/arch/mips/ps2/dma.h
--- linux-2.6.21.1.orig/arch/mips/ps2/dma.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/dma.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,65 @@
+//---------------------------------------------------------------------------
+// File:	dma.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Playstation2 DMA Convenience Routines and Macros
+//---------------------------------------------------------------------------
+// * Data is transfered in qword (128bit, 16bytes) units
+// * Data should be aligned on qword boundary (.align 7, aligned(16))
+//---------------------------------------------------------------------------
+#ifndef DMA_H
+#define DMA_H
+
+#include "defines.h"
+#include "regs.h"
+
+
+extern void dma_reset(void);
+
+//---------------------------------------------------------------------------
+// CHCR Register - Channel Control Register
+//---------------------------------------------------------------------------
+#define GIF_CHCR		((volatile uint32 *)(gif_chcr))
+
+#define SET_CHCR(WHICH,DIR,MOD,ASP,TTE,TIE,STR,TAG) \
+	*WHICH = \
+	((uint32)(DIR)	<< 0)		| \
+	((uint32)(MOD)	<< 2)		| \
+	((uint32)(ASP)	<< 4)		| \
+	((uint32)(TTE)	<< 6)		| \
+	((uint32)(TIE)	<< 7)		| \
+	((uint32)(STR)	<< 8)		| \
+	((uint32)(TAG)	<< 16)
+
+#define DMA_WAIT(WHICH) \
+	while((*WHICH) & (1<<8))
+
+//---------------------------------------------------------------------------
+// MADR Register - Transfer Address Register
+//---------------------------------------------------------------------------
+#define GIF_MADR		((volatile uint32 *)(gif_madr))
+
+#define SET_MADR(WHICH,ADDR,SPR) \
+	*WHICH = \
+	((uint32)(ADDR)	<< 0)		| \
+	((uint32)(SPR)	<< 31)
+
+//---------------------------------------------------------------------------
+// TADR Register - Tag Address Register
+//---------------------------------------------------------------------------
+#define GIF_TADR		((volatile uint32 *)(gif_tadr))
+
+#define SET_TADR(WHICH,ADDR,SPR) \
+	*WHICH = \
+	((uint32)(ADDR)	<< 0)		| \
+	((uint32)(SPR)	<< 31)
+
+//---------------------------------------------------------------------------
+// QWC Register - Transfer Data Size Register
+//---------------------------------------------------------------------------
+#define GIF_QWC		((volatile uint32 *)(gif_qwc))
+
+#define SET_QWC(WHICH,SIZE) \
+	*WHICH = (uint32)(SIZE)
+
+#endif // DMA_H
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/dma.S linux-2.6.21.1/arch/mips/ps2/dma.S
--- linux-2.6.21.1.orig/arch/mips/ps2/dma.S	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/dma.S	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,51 @@
+#------------------------------------------------------------------------
+# File:		dma_asm.s
+# Author:	Tony Saveski, t_saveski@yahoo.com
+# Notes:	DMA routines implemented in assembler
+#------------------------------------------------------------------------
+
+#include "regs.h"
+
+#------------------------------------------------------------------------
+.set noreorder
+
+.text
+.globl dma_reset
+
+#------------------------------------------------------------------------
+# void dma_reset();
+#------------------------------------------------------------------------
+# Ripped straight from 3stars or something. Will 'clean up later'.
+#------------------------------------------------------------------------
+.align 7
+.ent dma_reset
+dma_reset:
+	lui	$2,0x1000
+	ori	$2,$2,0xA000
+	sw	$0,0($2)
+	sw	$0,0x10($2)
+	sw	$0,0x20($2)
+	sw	$0,0x30($2)
+	sw	$0,0x40($2)
+	sw	$0,0x50($2)
+	
+	xori	$2,$2,0xA000 #annulla la seconda parte
+	ori	$2,$2,0xE000 #ne metto un'altra
+	lw	$3,0x10($2)
+	sw	$0,0x0($2)
+	sw	$3,0x10($2)
+	sw	$0,0x20($2)
+	sw	$0,0x30($2)
+	sw	$0,0x40($2)
+	sw	$0,0x50($2)
+
+	lw	$3,0x0($2)
+	nop 			#load delay
+	ori	$3,$3,0x1
+	sw	$3,0x0($2)
+
+	and	$2,$0,$0
+	jr	ra
+	nop
+.end dma_reset
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/g2.c linux-2.6.21.1/arch/mips/ps2/g2.c
--- linux-2.6.21.1.orig/arch/mips/ps2/g2.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/g2.c	2007-06-01 21:50:31.000000000 +0200
@@ -0,0 +1,270 @@
+//---------------------------------------------------------------------------
+// File:	g2.c
+// Author:	Tony Saveski, t_saveski@yahoo.com
+//---------------------------------------------------------------------------
+#include "g2.h"
+#include "ps2.h"
+#include "dma.h"
+#include "gs.h"
+#include "gif.h"
+
+// int_mode
+#define NON_INTERLACED	0
+#define INTERLACED		1
+
+// ntsc_pal
+#define NTSC			2
+#define PAL				3
+
+// field_mode
+#define FRAME			1
+#define FIELD			2
+//extern int a;
+//---------------------------------------------------------------------------
+#define vSMODE1(VHP,VCKSEL,SLCK2,NVCK,CLKSEL,PEVS,PEHS,PVS,PHS,GCONT,SPML,PCK2,XPCK,SINT,PRST,EX,CMOD,SLCK,T1248,LC,RC) \
+        (((u64)(VHP)<<36)   | ((u64)(VCKSEL)<<34) | ((u64)(SLCK2)<<33) | \
+         ((u64)(NVCK)<<32)  | ((u64)(CLKSEL)<<30) | ((u64)(PEVS)<<29)  | \
+         ((u64)(PEHS)<<28)  | ((u64)(PVS)<<27)    | ((u64)(PHS)<<26)   | \
+         ((u64)(GCONT)<<25) | ((u64)(SPML)<<21)   | ((u64)(PCK2)<<19)  | \
+         ((u64)(XPCK)<<18)  | ((u64)(SINT)<<17)   | ((u64)(PRST)<<16)  | \
+         ((u64)(EX)<<15)    | ((u64)(CMOD)<<13)   | ((u64)(SLCK)<<12)  | \
+         ((u64)(T1248)<<10) | ((u64)(LC)<<3)      | ((u64)(RC)<<0))
+#define vSYNCH1(HS,HSVS,HSEQ,HBP,HFP)   \
+        (((u64)(HS)<<43) | ((u64)(HSVS)<<32) | ((u64)(HSEQ)<<22) | \
+         ((u64)(HBP)<<11) | ((u64)(HFP)<<0))
+#define vSYNCH2(HB,HF) \
+        (((u64)(HB)<<11) | ((u64)(HF)<<0))
+#define vSYNCV(VS,VDP,VBPE,VBP,VFPE,VFP) \
+        (((u64)(VS)<<53) | ((u64)(VDP)<<42) | ((u64)(VBPE)<<32) | \
+         ((u64)(VBP)<<20) | ((u64)(VFPE)<<10) | ((u64)(VFP)<<0))
+
+const unsigned char letters[][8]={
+{0x00,0x3C,0x42,0x42,0x42,0x7E,0x42,0x42},
+{0x00,0x7C,0x42,0x42,0x7c,0x42,0x42,0x7C},
+{0x00,0x3C,0x40,0x40,0x40,0x40,0x40,0x3C},
+{0x00,0x7C,0x42,0x42,0x42,0x42,0x42,0x7C},
+{0x00,0x7C,0x40,0x40,0x78,0x40,0x40,0x7C}
+};
+
+typedef struct
+{
+	uint16 ntsc_pal;
+	uint16 width;
+	uint16 height;
+	uint16 psm;
+	uint16 bpp;
+	uint16 magh;
+	uint16 pad1;
+	uint16 pad2;
+} vmode_t __attribute__((aligned(16)));
+
+vmode_t vmodes[] = {
+	 {PAL, 256, 256, 0, 32, 10,0,0},	// PAL_256_512_32
+	{PAL, 320, 256, 0, 32, 8,0,0},	// PAL_320_256_32
+	{PAL, 384, 256, 0, 32, 7,0,0},	// PAL_384_256_32
+	{PAL, 512, 256, 0, 32, 5,0,0},	// PAL_512_256_32
+	{PAL, 640, 256, 0, 32, 4,0,0}	// PAL_640_256_32
+};
+
+static vmode_t *cur_mode;
+
+//---------------------------------------------------------------------------
+static uint16	g2_max_x=0;		// current resolution max coordinates
+static uint16	g2_max_y=0;
+
+static uint8	g2_col_r=0;		// current draw color
+static uint8	g2_col_g=0;
+static uint8	g2_col_b=0;
+
+static uint8	g2_fill_r=0;	// current fill color
+static uint8	g2_fill_g=0;
+static uint8	g2_fill_b=0;
+
+//---------------------------------------------------------------------------
+DECLARE_GS_PACKET(gs_dma_buf,50);
+
+//---------------------------------------------------------------------------
+int g2_init(g2_video_mode mode)
+{
+vmode_t *v;
+
+	v = &(vmodes[mode]);
+	cur_mode = v;
+
+	g2_max_x = v->width - 1;
+	g2_max_y = v->height - 1;
+
+	// - Initialize the DMA. 
+	// - Writes a 0 to most of the DMA registers.
+	dma_reset();
+
+	// - Sets the RESET bit if the GS CSR register.
+	GS_RESET();
+	// - Can someone please tell me what the sync.p 
+	// instruction does. Synchronizes something :-)
+	__asm__("sync.p; nop;");
+
+	// - Sets up the GS IMR register (i guess).
+	// - The IMR register is used to mask and unmask certain interrupts,
+	//   for example VSync and VSync. We'll use this properly in Tutorial 2.
+	// - Does anyone have code to do this without using the 0x71 syscall?
+	// - I havn't gotten around to looking at any PS2 bios code yet.
+	gs_set_imr();
+	
+	// - Use syscall 0x02 to setup some video mode stuff.
+	// - Pretty self explanatory I think.
+	// - Does anyone have code to do this without using the syscall? It looks
+	//   like it should only set the SMODE2 register, but if I remove this syscall
+	//   and set the SMODE2 register myself, it donesn't work. What else does 
+	//   syscall 0x02 do?
+	gs_set_crtc(NON_INTERLACED, v->ntsc_pal, FRAME);
+
+	// - I havn't attempted to understand what the Alpha parameters can do. They
+	//   have been blindly copied from the 3stars demo (although they don't seem 
+	//   do have any impact in this simple 2D code.
+	GS_SET_PMODE(
+		1,		// ReadCircuit1 OFF 
+		0,		// ReadCircuit2 ON
+		1,		// Use ALP register for Alpha Blending
+		1,		// Alpha Value of ReadCircuit2 for output selection
+		0,		// Blend Alpha with the output of ReadCircuit2
+		0xFF	// Alpha Value = 1.0
+	);
+	GS_SET_DISPFB1(
+		0,				// Frame Buffer base pointer = 0 (Address/2048)
+		v->width/64,	// Buffer Width (Address/64)
+		v->psm,			// Pixel Storage Format
+		0,				// Upper Left X in Buffer = 0
+		0				// Upper Left Y in Buffer = 0
+	);
+
+	// Why doesn't (0, 0) equal the very top-left of the TV?
+	GS_SET_DISPLAY1(
+		656,		// X position in the display area (in VCK units)
+		36,			// Y position in the display area (in Raster units)
+		v->magh-1,	// Horizontal Magnification - 1
+		0,						// Vertical Magnification = 1x
+		v->width*v->magh-1,		// Display area width  - 1 (in VCK units) (Width*HMag-1)
+		v->height-1				// Display area height - 1 (in pixels)	  (Height-1)
+	);
+
+	GS_SET_BGCOLOR(
+		0,	// RED
+		0,	// GREEN
+		0	// BLUE
+	);
+
+
+	BEGIN_GS_PACKET(gs_dma_buf);
+
+	GIF_TAG_AD(gs_dma_buf, 3, 1, 0, 0, 0);
+
+	GIF_DATA_AD(gs_dma_buf, frame_1,
+		GS_FRAME(
+			0,					// FrameBuffer base pointer = 0 (Address/2048)
+			v->width/64,		// Frame buffer width (Pixels/64)
+			v->psm,				// Pixel Storage Format
+			0));
+
+	// No displacement between Primitive and Window coordinate systems.
+	GIF_DATA_AD(gs_dma_buf, xyoffset_1,
+		GS_XYOFFSET(
+			0x0,
+			0x0));
+
+	// Clip to frame buffer.
+	GIF_DATA_AD(gs_dma_buf, scissor_1,
+		GS_SCISSOR(
+			0,
+			g2_max_x,
+			0,
+			g2_max_y));
+
+	SEND_GS_PACKET(gs_dma_buf);
+	return 1;
+}
+
+//---------------------------------------------------------------------------
+void g2_end(void)
+{
+	GS_RESET();
+}
+
+//---------------------------------------------------------------------------
+
+void g2_put_pixel(uint16 x, uint16 y)
+{
+	BEGIN_GS_PACKET(gs_dma_buf);
+
+	GIF_TAG_AD(gs_dma_buf, 4, 1, 0, 0, 0);
+
+	GIF_DATA_AD(gs_dma_buf, prim,
+		GS_PRIM(PRIM_POINT, 0, 0, 0, 0, 0, 0, 0, 0));
+	
+	GIF_DATA_AD(gs_dma_buf, rgbaq,	
+		GS_RGBAQ(g2_col_r, g2_col_g, g2_col_b, 0, 0));
+
+	// The XYZ coordinates are actually floating point numbers between
+	// 0 and 4096 represented as unsigned integers where the lowest order
+	// four bits are the fractional point. That's why all coordinates are
+	// shifted left 4 bits.
+	GIF_DATA_AD(gs_dma_buf, xyz2, GS_XYZ2(x<<4, y<<4, 0));
+
+	SEND_GS_PACKET(gs_dma_buf);
+}
+
+//---------------------------------------------------------------------------
+void g2_fill_rect(uint16 x0, uint16 y0, uint16 x1, uint16 y1)
+{
+	BEGIN_GS_PACKET(gs_dma_buf);
+
+	GIF_TAG_AD(gs_dma_buf, 4, 1, 0, 0, 0);
+
+	GIF_DATA_AD(gs_dma_buf, prim,
+		GS_PRIM(PRIM_SPRITE, 0, 0, 0, 0, 0, 0, 0, 0));
+	
+	GIF_DATA_AD(gs_dma_buf, rgbaq,	
+		GS_RGBAQ(g2_fill_r, g2_fill_g, g2_fill_b, 0, 0));
+
+	// The XYZ coordinates are actually floating point numbers between
+	// 0 and 4096 represented as unsigned integers where the lowest order
+	// four bits are the fractional point. That's why all coordinates are
+	// shifted left 4 bits.
+	GIF_DATA_AD(gs_dma_buf, xyz2, GS_XYZ2(x0<<4, y0<<4, 0));
+
+	// It looks like the default operation for the SPRITE primitive is to
+	// not draw the right and bottom 'lines' of the rectangle refined by
+	// the parameters. Add +1 to change this.
+	GIF_DATA_AD(gs_dma_buf, xyz2, GS_XYZ2((x1+1)<<4, (y1+1)<<4, 0));
+
+	SEND_GS_PACKET(gs_dma_buf);
+}
+
+//---------------------------------------------------------------------------
+uint16 g2_get_max_x(void)
+{
+	return(g2_max_x);
+}
+
+//---------------------------------------------------------------------------
+uint16 g2_get_max_y(void)
+{
+	return(g2_max_y);
+}
+
+//---------------------------------------------------------------------------
+void g2_set_color(uint8 r, uint8 g, uint8 b)
+{
+	g2_col_r = r;
+	g2_col_g = g;
+	g2_col_b = b;
+}
+
+//---------------------------------------------------------------------------
+void g2_set_fill_color(uint8 r, uint8 g, uint8 b)
+{
+	g2_fill_r = r;
+	g2_fill_g = g;
+	g2_fill_b = b;
+}
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/g2.h linux-2.6.21.1/arch/mips/ps2/g2.h
--- linux-2.6.21.1.orig/arch/mips/ps2/g2.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/g2.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,33 @@
+//---------------------------------------------------------------------------
+// File:	g2.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Simple 'High Level' 2D Graphics Library
+//---------------------------------------------------------------------------
+#ifndef G2_H
+#define G2_H
+
+#include "defines.h"
+
+typedef enum {
+	 PAL_256_256_32=0
+	,PAL_320_256_32
+	,PAL_384_256_32
+	,PAL_512_256_32
+	,PAL_640_256_32
+} g2_video_mode;
+
+extern int g2_init(g2_video_mode mode);
+extern void g2_end(void);
+
+extern uint16 g2_get_max_x(void);
+extern uint16 g2_get_max_y(void);
+extern void g2_write(uint16 x,uint16 y,char* str);
+
+extern void g2_set_color(uint8 r, uint8 g, uint8 b);
+extern void g2_set_fill_color(uint8 r, uint8 g, uint8 b);
+
+extern void g2_put_pixel(uint16 x, uint16 y);
+extern void g2_fill_rect(uint16 x0, uint16 y0, uint16 x1, uint16 y1);
+
+#endif // G2_H
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/gif.h linux-2.6.21.1/arch/mips/ps2/gif.h
--- linux-2.6.21.1.orig/arch/mips/ps2/gif.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/gif.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,54 @@
+//---------------------------------------------------------------------------
+// File:	gif.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Macros to create and populate DMA buffers to send to the PS2 GIF
+//---------------------------------------------------------------------------
+#ifndef GIF_H
+#define GIF_H
+
+#include "defines.h"
+#include "regs.h"
+
+//---------------------------------------------------------------------------
+#define GIF_AD		0x0e
+#define GIF_NOP		0x0f
+
+//---------------------------------------------------------------------------
+// GS_PACKET macros
+//---------------------------------------------------------------------------
+
+#define DECLARE_GS_PACKET(NAME,ITEMS) \
+	uint64 __attribute__((aligned(64))) NAME[ITEMS*2+2]; \
+	int NAME##_cur; \
+	int NAME##_dma_size
+
+#define BEGIN_GS_PACKET(NAME) \
+	NAME##_cur = 0
+
+#define GIF_TAG(NAME,NLOOP,EOP,PRE,PRIM,FLG,NREG,REGS) \
+	NAME##_dma_size = NLOOP+1; \
+	NAME[NAME##_cur++] = \
+		((uint64)(NLOOP)<< 0)		| \
+		((uint64)(EOP)	<< 15)		| \
+		((uint64)(PRE)	<< 46)		| \
+		((uint64)(PRIM)	<< 47)		| \
+		((uint64)(FLG)	<< 58)		| \
+		((uint64)(NREG)	<< 60);		\
+	NAME[NAME##_cur++] = (uint64)REGS
+
+#define GIF_TAG_AD(NAME,NLOOP,EOP,PRE,PRIM,FLG) \
+	GIF_TAG(NAME,NLOOP,EOP,PRE,PRIM,FLG,1,GIF_AD)
+
+#define GIF_DATA_AD(NAME,REG,DAT) \
+	NAME[NAME##_cur++] = (uint64)DAT; \
+	NAME[NAME##_cur++] = (uint64)REG
+
+#define SEND_GS_PACKET(NAME) \
+	ps2_flush_cache(0);							\
+	SET_QWC(GIF_QWC, NAME##_dma_size);			\
+	SET_MADR(GIF_MADR, &(NAME), 0);				\
+	SET_CHCR(GIF_CHCR, 1, 0, 0, 0, 0, 1, 0);	\
+	DMA_WAIT(GIF_CHCR)
+
+#endif // GIF_H
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/gs.h linux-2.6.21.1/arch/mips/ps2/gs.h
--- linux-2.6.21.1.orig/arch/mips/ps2/gs.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/gs.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,158 @@
+//---------------------------------------------------------------------------
+// File:	gs.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Playstation2 GS Convenience Routines
+//---------------------------------------------------------------------------
+#ifndef GS_H
+#define GS_H
+
+#include "defines.h"
+#include "regs.h"
+
+extern void gs_set_imr(void);
+extern void gs_set_crtc(uint8 int_mode, uint8 ntsc_pal, uint8 field_mode);
+extern void ps2_flush_cache(int);
+
+//---------------------------------------------------------------------------
+// CSR Register
+//---------------------------------------------------------------------------
+#define CSR			((volatile uint64 *)(csr))
+#define GS_SET_CSR(SIGNAL,FINISH,HSINT,VSINT,EDWINT,FLUSH,RESET,NFIELD,FIELD,FIFO,REV,ID) \
+	*CSR = \
+	((uint64)(SIGNAL)	<< 0)		| \
+	((uint64)(FINISH)	<< 1)		| \
+	((uint64)(HSINT)	<< 2)		| \
+	((uint64)(VSINT)	<< 3)		| \
+	((uint64)(EDWINT)	<< 4)		| \
+	((uint64)(FLUSH)	<< 8)		| \
+	((uint64)(RESET)	<< 9)		| \
+	((uint64)(NFIELD)	<< 12)		| \
+	((uint64)(FIELD)	<< 13)		| \
+	((uint64)(FIFO)		<< 14)		| \
+	((uint64)(REV)		<< 16)		| \
+	((uint64)(ID)		<< 24)
+
+#define GS_RESET() \
+	*CSR = ((uint64)(1)	<< 9)
+
+//---------------------------------------------------------------------------
+// PMODE Register
+//---------------------------------------------------------------------------
+#define PMODE		((volatile uint64 *)(pmode))
+#define GS_SET_PMODE(EN1,EN2,MMOD,AMOD,SLBG,ALP) \
+	*PMODE = \
+	((uint64)(EN1) 	<< 0) 	| \
+	((uint64)(EN2) 	<< 1) 	| \
+	((uint64)(001)	<< 2) 	| \
+	((uint64)(MMOD)	<< 5) 	| \
+	((uint64)(AMOD) << 6) 	| \
+	((uint64)(SLBG) << 7) 	| \
+	((uint64)(ALP) 	<< 8)
+
+//---------------------------------------------------------------------------
+// SMODE2 Register
+//---------------------------------------------------------------------------
+#define SMODE2		((volatile uint64 *)(smode2))
+#define GS_SET_SMODE2(INT,FFMD,DPMS) \
+	*SMODE2 = \
+	((uint64)(INT)	<< 0)	| \
+	((uint64)(FFMD)	<< 1)	| \
+	((uint64)(DPMS)	<< 2)
+
+//---------------------------------------------------------------------------
+// DISPFP1 Register
+//---------------------------------------------------------------------------
+#define DISPFB1		((volatile uint64 *)(dispfb1))
+#define GS_SET_DISPFB1(FBP,FBW,PSM,DBX,DBY) \
+	*DISPFB1 = \
+	((uint64)(FBP)	<< 0)	| \
+	((uint64)(FBW)	<< 9)	| \
+	((uint64)(PSM)	<< 15)	| \
+	((uint64)(DBX)	<< 32)	| \
+	((uint64)(DBY)	<< 43)
+
+//---------------------------------------------------------------------------
+// DISPLAY1 Register
+//---------------------------------------------------------------------------
+#define DISPLAY1	((volatile uint64 *)(display1))
+#define GS_SET_DISPLAY1(DX,DY,MAGH,MAGV,DW,DH) \
+	*DISPLAY1 = \
+	((uint64)(DX)	<< 0)	| \
+	((uint64)(DY)	<< 12)	| \
+	((uint64)(MAGH)	<< 23)	| \
+	((uint64)(MAGV)	<< 27)	| \
+	((uint64)(DW)	<< 32)	| \
+	((uint64)(DH)	<< 44)
+
+//---------------------------------------------------------------------------
+// BGCOLOR Register
+//---------------------------------------------------------------------------
+#define BGCOLOR		((volatile uint64 *)(bgcolor))
+#define GS_SET_BGCOLOR(R,G,B) \
+	*BGCOLOR = \
+	((uint64)(R)	<< 0)		| \
+	((uint64)(G)	<< 8)		| \
+	((uint64)(B)	<< 16)
+
+//---------------------------------------------------------------------------
+// FRAME_x Register
+//---------------------------------------------------------------------------
+#define GS_FRAME(FBP,FBW,PSM,FBMSK) \
+	(((uint64)(FBP)		<< 0)		| \
+	 ((uint64)(FBW)		<< 16)		| \
+	 ((uint64)(PSM)		<< 24)		| \
+	 ((uint64)(FBMSK)	<< 32))
+
+//---------------------------------------------------------------------------
+// PRIM Register
+//---------------------------------------------------------------------------
+#define PRIM_POINT			0
+#define PRIM_SPRITE			6
+
+#define GS_PRIM(PRI,IIP,TME,FGE,ABE,AA1,FST,CTXT,FIX) \
+	(((uint64)(PRI)		<< 0)		| \
+	 ((uint64)(IIP)		<< 3)		| \
+	 ((uint64)(TME)		<< 4)		| \
+	 ((uint64)(FGE)		<< 5)		| \
+	 ((uint64)(ABE)		<< 6)		| \
+	 ((uint64)(AA1)		<< 7)		| \
+	 ((uint64)(FST)		<< 8)		| \
+	 ((uint64)(CTXT)	<< 9)		| \
+	 ((uint64)(FIX)		<< 10))
+
+//---------------------------------------------------------------------------
+// RGBAQ Register
+//---------------------------------------------------------------------------
+#define GS_RGBAQ(R,G,B,A,Q) \
+	(((uint64)(R)		<< 0)		| \
+	 ((uint64)(G)		<< 8)		| \
+	 ((uint64)(B)		<< 16)		| \
+	 ((uint64)(A)		<< 24)		| \
+	 ((uint64)(Q)		<< 32))
+
+//---------------------------------------------------------------------------
+// SCISSOR_x Register
+//---------------------------------------------------------------------------
+#define GS_SCISSOR(X0,X1,Y0,Y1) \
+	(((uint64)(X0)		<< 0)		| \
+	 ((uint64)(X1)		<< 16)		| \
+	 ((uint64)(Y0)		<< 32)		| \
+	 ((uint64)(Y1)		<< 48))
+
+//---------------------------------------------------------------------------
+// XYZ2 Register
+//---------------------------------------------------------------------------
+#define GS_XYZ2(X,Y,Z)	\
+	(((uint64)(X)		<< 0)		| \
+	 ((uint64)(Y)		<< 16)		| \
+	 ((uint64)(Z)		<< 32))
+
+//---------------------------------------------------------------------------
+// XYOFFSET_x Register
+//---------------------------------------------------------------------------
+#define GS_XYOFFSET(OFX,OFY)	\
+	(((uint64)(OFX)		<< 0)		| \
+	 ((uint64)(OFY)		<< 32))
+
+#endif // GS_H
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/gs.S linux-2.6.21.1/arch/mips/ps2/gs.S
--- linux-2.6.21.1.orig/arch/mips/ps2/gs.S	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/gs.S	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,47 @@
+#------------------------------------------------------------------------
+# File:		gs_asm.s
+# Author:	Tony Saveski, t_saveski@yahoo.com
+# Notes:	GS routines implemented in assembler
+#------------------------------------------------------------------------
+
+#include "regs.h"
+
+#------------------------------------------------------------------------
+.set noreorder
+
+.text
+.globl gs_set_imr
+.globl gs_set_crtc
+
+#------------------------------------------------------------------------
+# void gs_set_imr(void);
+#------------------------------------------------------------------------
+.align 7
+.ent gs_set_imr
+gs_set_imr:
+	lui		$3,0x1200
+	sw		$2,0x1010($3)
+
+	xor	v0,zero,zero	# return 0
+	jr		ra
+	nop
+.end gs_set_imr
+
+#------------------------------------------------------------------------
+# void gs_set_crtc(uint8 int_mode, uint8 ntsc_pal, uint8 field_mode);
+#------------------------------------------------------------------------
+.align 7
+.ent gs_set_crtc
+gs_set_crtc:
+	li		v1,0x02			# call SetGsCrt
+	syscall
+	nop
+#	lui	$3,0x1200
+#	ori	$2,$0,0b1110
+#	sw	$2,0x20($3)
+
+	xor	v0,zero,zero	# return 0
+	jr		ra
+	nop
+.end gs_set_crtc
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/init.c linux-2.6.21.1/arch/mips/ps2/init.c
--- linux-2.6.21.1.orig/arch/mips/ps2/init.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/init.c	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,4 @@
+const char* get_system_type()
+{
+	return "Sony Playstation 2";
+}
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/irq.c linux-2.6.21.1/arch/mips/ps2/irq.c
--- linux-2.6.21.1.orig/arch/mips/ps2/irq.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/irq.c	2007-06-07 17:42:51.000000000 +0200
@@ -0,0 +1,17 @@
+#include <linux/init.h>
+#include <linux/interrupt.h>
+void __init arch_init_irq(void)
+{
+        /* do board-specific irq initialization */
+//	graphik("ba");
+}
+
+asmlinkage void plat_irq_dispatch(void)
+{
+	graphik("bb");
+}
+
+void __init plat_timer_setup(struct irqaction *irq)
+{
+//	graphik("bc");
+}
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/Makefile linux-2.6.21.1/arch/mips/ps2/Makefile
--- linux-2.6.21.1.orig/arch/mips/ps2/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/Makefile	2007-06-07 18:58:52.000000000 +0200
@@ -0,0 +1,7 @@
+obj-y                           += setup.o irq.o prom.o init.o g2.o \
+				   ps2.o dma.o gs.o console.o
+
+#%.o: %.s
+#	@echo "-------------------------------------------------"
+#	$(CC) -xassembler-with-cpp -c $(CFLAGS) $< -o $@
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/prom.c linux-2.6.21.1/arch/mips/ps2/prom.c
--- linux-2.6.21.1.orig/arch/mips/ps2/prom.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/prom.c	2007-06-05 23:20:58.000000000 +0200
@@ -0,0 +1,71 @@
+#include <linux/init.h>
+#include <linux/font.h>
+#include <linux/kernel.h>
+#include "g2.h"
+
+void graphik(char* s);
+static int x,y;
+void __init prom_init(void)
+{
+        /* get whatever info we need from the PROM */
+	/* Prima funzione*/
+	x=0;
+	y=0;
+        g2_init(PAL_640_256_32);
+        g2_set_fill_color(0, 0, 0);
+        g2_fill_rect(0, 0, g2_get_max_x(), g2_get_max_y());
+	g2_set_color(255,255,255);
+	console_loglevel=10;
+	__asm__("mfc0 $2,$12; lui $3,0xffff; ori $3,0xffe7; and $2,$2,$3; mtc0 $2,$12; sync.p; nop;");
+}
+
+unsigned long prom_free_prom_memory(void)
+{
+	graphik("b");
+        return 0; /* "Freeing unused memory: %ldk freed\n" */
+}
+
+void prom_putchar(char c)
+{
+	unsigned char* fontdata_8x8=font_vga_8x8.data;
+	int i,j;
+	if(c=='\n')
+	{
+		x=0;
+		y+=8;
+	}
+	else if(c!='\r')
+	{
+		for(i=0;i<8;i++)
+		{
+			for(j=0;j<8;j++)
+			{
+				if(fontdata_8x8[c*8+i]&(1<<(7-j)))
+					g2_put_pixel(x+j,y+i);
+			}
+		}
+		x+=8;
+	}
+}
+
+void graphik(char* s)
+{
+	g2_write(x,y,s);
+	while(1);
+}
+
+void autogr()
+{
+	graphik("ccc");
+}
+
+void g2_write(uint16 x,uint16 y,char* str)
+{
+	int c;
+	c=0;
+	while(str[c]!='\0')
+	{
+		prom_putchar(str[c]);
+		c++;
+	}
+}
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/ps2.h linux-2.6.21.1/arch/mips/ps2/ps2.h
--- linux-2.6.21.1.orig/arch/mips/ps2/ps2.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/ps2.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,21 @@
+//---------------------------------------------------------------------------
+// File:	ps2.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Note:	PS2 System Routines
+//---------------------------------------------------------------------------
+#ifndef PS2_H
+#define PS2_H
+
+#include "defines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void ps2_flush_cache(int blah);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PS2_H
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/ps2.S linux-2.6.21.1/arch/mips/ps2/ps2.S
--- linux-2.6.21.1.orig/arch/mips/ps2/ps2.S	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/ps2.S	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,26 @@
+#------------------------------------------------------------------------
+# File:		ps2_asm.s
+# Author:	Tony Saveski, t_saveski@yahoo.com
+# Notes:	PS2 System routines implemented in assembler
+#------------------------------------------------------------------------
+
+#include "regs.h"
+
+#------------------------------------------------------------------------
+.set noreorder
+
+.text
+.globl ps2_flush_cache
+
+#------------------------------------------------------------------------
+# void ps2_flush_cache(int); 			Flushes the PS2 Data Cache.
+#------------------------------------------------------------------------
+.align 7
+.ent ps2_flush_cache
+ps2_flush_cache:
+	li	$3,100
+	syscall
+	jr	$31
+	nop
+.end ps2_flush_cache
+
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/regs.h linux-2.6.21.1/arch/mips/ps2/regs.h
--- linux-2.6.21.1.orig/arch/mips/ps2/regs.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/regs.h	2007-05-31 20:16:37.000000000 +0200
@@ -0,0 +1,121 @@
+//------------------------------------------------------------------------
+// File:	regs.h
+// Author:	Tony Saveski, t_saveski@yahoo.com
+// Notes:	Playstation 2 Register Definitions
+//------------------------------------------------------------------------
+#ifndef REGS_H
+#define REGS_H
+
+// MIPS CPU Registsers
+#define zero	$0		// Always 0
+#define at		$1		// Assembler temporary
+#define v0		$2		// Function return
+#define v1		$3		// 
+#define a0		$4		// Function arguments
+#define a1		$5
+#define a2		$6
+#define a3		$7
+#define t0		$8		// Temporaries. No need
+#define t1		$9		// to preserve in your
+#define t2		$10		// functions.
+#define t3		$11
+#define t4		$12
+#define t5		$13
+#define t6		$14
+#define t7		$15
+#define s0		$16		// Saved Temporaries.
+#define s1		$17		// Make sure to restore
+#define s2		$18		// to original value
+#define s3		$19		// if your function
+#define s4		$20		// changes their value.
+#define s5		$21
+#define s6		$22
+#define s7		$23
+#define t8		$24		// More Temporaries.
+#define t9		$25
+#define k0		$26		// Reserved for Kernel
+#define k1		$27
+#define gp		$28		// Global Pointer
+#define sp		$29		// Stack Pointer
+#define fp		$30		// Frame Pointer
+#define ra		$31		// Function Return Address
+
+// Playstation2 GS Privileged Registers
+#define pmode		0x12000000	// Setup CRT Controller
+#define smode2		0x12000020	// CRTC Video Settings: PAL/NTCS, Interlace, etc.
+#define dispfb1		0x12000070	// Setup the CRTC's Read Circuit 1 data source settings
+#define display1	0x12000080	// RC1 display output settings
+#define dispfb2		0x12000090	// Setup the CRTC's Read Circuit 2 data source settings
+#define display2	0x120000a0	// RC2 display output settings
+#define extbuf		0x120000b0	// ...
+#define extdata		0x120000c0	// ...
+#define extwrite	0x120000d0	// ...
+#define bgcolor		0x120000e0	// Set CRTC background color
+#define csr			0x12001000	// System status and reset
+#define imr			0x12001010	// Interrupt Mask Register
+#define busdir		0x12001040	// ...
+#define siglblid	0x12001080	// ...
+
+// Playstation2 GS General Purpose Registers
+#define prim		0x00	// Select and configure current drawing primitive
+#define rgbaq		0x01	// Setup current vertex color
+#define st			0x02	// ...
+#define uv			0x03	// ...
+#define xyzf2		0x04	// Set vertex coordinate
+#define xyz2		0x05	// Set vertex coordinate and 'kick' drawing
+#define tex0_1		0x06	// ...
+#define tex0_2		0x07	// ...
+#define clamp_1		0x08	// ...
+#define clamp_2		0x09	// ...
+#define fog			0x0a	// ...
+#define xyzf3		0x0c	// ...
+#define xyz3		0x0d	// ...
+#define tex1_1		0x14	// ...
+#define tex1_2		0x15	// ...
+#define tex2_1		0x16	// ...
+#define tex2_2		0x17	// ...
+#define xyoffset_1	0x18	// Mapping from Primitive to Window coordinate system (Context 1)
+#define xyoffset_2	0x19	// Mapping from Primitive to Window coordinate system (Context 2)
+#define prmodecont	0x1a	// ...
+#define prmode		0x1b	// ...
+#define texclut		0x1c	// ...
+#define scanmsk		0x22	// ...
+#define miptbp1_1	0x34	// ...
+#define miptbp1_2	0x35	// ...
+#define miptbp2_1	0x36	// ...
+#define miptbp2_2	0x37	// ...
+#define texa		0x3b	// ...
+#define fogcol		0x3d	// ...
+#define texflush	0x3f	// ...
+#define scissor_1	0x40	// Setup clipping rectangle (Context 1)
+#define scissor_2	0x41	// Setup clipping rectangle (Context 2)
+#define alpha_1		0x42	// ...
+#define alpha_2		0x43	// ...
+#define dimx		0x44	// ...
+#define dthe		0x45	// ...
+#define colclamp	0x46	// ...
+#define test_1		0x47	// ...
+#define test_2		0x48	// ...
+#define pabe		0x49	// ...
+#define fba_1		0x4a	// ...
+#define fba_2		0x4b	// ...
+#define frame_1		0x4c	// Frame buffer settings (Context 1)
+#define frame_2		0x4d	// Frame buffer settings (Context 2)
+#define zbuf_1		0x4e	// ...
+#define zbuf_2		0x4f	// ...
+#define bitbltbuf	0x50	// ...
+#define trxpos		0x51	// ...
+#define trxreg		0x52	// ...
+#define trxdir		0x53	// ...
+#define hwreg		0x54	// ...
+#define signal		0x60	// ...
+#define finish		0x61	// ...
+#define label		0x62	// ...
+
+// Playstation2 DMA Channel Registers
+#define gif_chcr	0x1000a000	// GIF Channel Control Register
+#define gif_madr	0x1000a010	// Transfer Address Register
+#define gif_qwc		0x1000a020	// Transfer Size Register (in qwords)
+#define gif_tadr	0x1000a030	// ...
+
+#endif // REGS_H
diff -ruN linux-2.6.21.1.orig/arch/mips/ps2/setup.c linux-2.6.21.1/arch/mips/ps2/setup.c
--- linux-2.6.21.1.orig/arch/mips/ps2/setup.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.21.1/arch/mips/ps2/setup.c	2007-06-07 18:58:40.000000000 +0200
@@ -0,0 +1,20 @@
+#include <linux/init.h>
+#include <linux/console.h>
+#include <asm-mips/bootinfo.h>
+#include <asm-mips/system.h>
+
+void __init plat_setup(void)
+{
+        /* do board-specific setup.. */
+	graphik("aa");
+}
+
+void __init plat_mem_setup(void)
+{
+	__asm__("mfc0 $2,$12; lui $3,0xffff; ori $3,0xffe7; and $2,$2,$3; mtc0 $2,$12; sync.p; nop;");
+	add_memory_region(0x0, 0x400000, BOOT_MEM_RAM);
+
+	conswitchp=&ps2_con;
+
+	local_irq_disable();
+}
diff -ruN linux-2.6.21.1.orig/include/asm-mips/addrspace.h linux-2.6.21.1/include/asm-mips/addrspace.h
--- linux-2.6.21.1.orig/include/asm-mips/addrspace.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/addrspace.h	2007-06-06 00:08:34.000000000 +0200
@@ -54,7 +54,8 @@
 #define XPHYSADDR(a)            ((_ACAST64_(a)) &			\
 				 _CONST64_(0x000000ffffffffff))
 
-#ifdef CONFIG_64BIT
+//#ifdef CONFIG_64BIT
+#if 0
 
 /*
  * Memory segments (64bit kernel mode addresses)
diff -ruN linux-2.6.21.1.orig/include/asm-mips/bootinfo.h linux-2.6.21.1/include/asm-mips/bootinfo.h
--- linux-2.6.21.1.orig/include/asm-mips/bootinfo.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/bootinfo.h	2007-05-31 20:16:37.000000000 +0200
@@ -207,6 +207,9 @@
 #define  MACH_TITAN_YOSEMITE	1	/* PMC-Sierra Yosemite		*/
 #define  MACH_TITAN_EXCITE	2	/* Basler eXcite		*/
 
+#define MACH_GROUP_SONY	       23
+#define  MACH_SONY_PS2		1
+
 /*
  * Valid machtype for group NEC EMMA2RH
  */
diff -ruN linux-2.6.21.1.orig/include/asm-mips/cpu.h linux-2.6.21.1/include/asm-mips/cpu.h
--- linux-2.6.21.1.orig/include/asm-mips/cpu.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/cpu.h	2007-06-03 23:23:24.000000000 +0200
@@ -61,6 +61,7 @@
 #define PRID_IMP_R4650		0x2200		/* Same as R4640 */
 #define PRID_IMP_R5000		0x2300
 #define PRID_IMP_TX49		0x2d00
+#define PRID_IMP_R5900		0x2e00
 #define PRID_IMP_SONIC		0x2400
 #define PRID_IMP_MAGIC		0x2500
 #define PRID_IMP_RM7000		0x2700
@@ -200,7 +201,8 @@
 #define CPU_SB1A		62
 #define CPU_74K			63
 #define CPU_R14000		64
-#define CPU_LAST		64
+#define CPU_R5900		65
+#define CPU_LAST		65
 
 /*
  * ISA Level encodings
diff -ruN linux-2.6.21.1.orig/include/asm-mips/delay.h linux-2.6.21.1/include/asm-mips/delay.h
--- linux-2.6.21.1.orig/include/asm-mips/delay.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/delay.h	2007-06-02 18:48:41.000000000 +0200
@@ -71,7 +71,7 @@
 		: "r" (usecs), "r" (lpj)
 		: GCC_REG_ACCUM);
 	else if (sizeof(long) == 8)
-		__asm__("dmultu\t%2, %3"
+		__asm__("multu\t%2, %3"
 		: "=h" (usecs), "=l" (lo)
 		: "r" (usecs), "r" (lpj)
 		: GCC_REG_ACCUM);
diff -ruN linux-2.6.21.1.orig/include/asm-mips/mach-generic/spaces.h linux-2.6.21.1/include/asm-mips/mach-generic/spaces.h
--- linux-2.6.21.1.orig/include/asm-mips/mach-generic/spaces.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/mach-generic/spaces.h	2007-06-07 12:38:51.000000000 +0200
@@ -11,7 +11,8 @@
 #define _ASM_MACH_GENERIC_SPACES_H
 
 
-#ifdef CONFIG_32BIT
+//#ifdef CONFIG_32BIT
+#ifdef CONFIG_64BIT
 
 #define CAC_BASE		0x80000000
 #define IO_BASE			0xa0000000
@@ -33,7 +34,8 @@
 
 #endif /* CONFIG_32BIT */
 
-#ifdef CONFIG_64BIT
+//#ifdef CONFIG_64BIT
+#if 0
 
 /*
  * This handles the memory map.
diff -ruN linux-2.6.21.1.orig/include/asm-mips/mipsregs.h linux-2.6.21.1/include/asm-mips/mipsregs.h
--- linux-2.6.21.1.orig/include/asm-mips/mipsregs.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/mipsregs.h	2007-06-07 16:46:03.000000000 +0200
@@ -619,13 +619,13 @@
 	else if (sel == 0)						\
 		__asm__ __volatile__(					\
 			".set\tmips3\n\t"				\
-			"dmfc0\t%0, " #source "\n\t"			\
+			"mfc0\t%0, " #source "\n\t"			\
 			".set\tmips0"					\
 			: "=r" (__res));				\
 	else								\
 		__asm__ __volatile__(					\
 			".set\tmips64\n\t"				\
-			"dmfc0\t%0, " #source ", " #sel "\n\t"		\
+			"mfc0\t%0, " #source ", " #sel "\n\t"		\
 			".set\tmips0"					\
 			: "=r" (__res));				\
 	__res;								\
@@ -652,7 +652,7 @@
 	else if (sel == 0)						\
 		__asm__ __volatile__(					\
 			".set\tmips3\n\t"				\
-			"dmtc0\t%z0, " #register "\n\t"			\
+			"mtc0\t%z0, " #register "\n\t"			\
 			".set\tmips0"					\
 			: : "Jr" (value));				\
 	else								\
diff -ruN linux-2.6.21.1.orig/include/asm-mips/page.h linux-2.6.21.1/include/asm-mips/page.h
--- linux-2.6.21.1.orig/include/asm-mips/page.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/asm-mips/page.h	2007-06-07 12:47:51.000000000 +0200
@@ -149,14 +149,14 @@
 /*
  * __pa()/__va() should be used only during mem init.
  */
-#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
-#define __pa_page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
-#else
+//#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
+//#define __pa_page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
+//#else
 #define __pa_page_offset(x)	PAGE_OFFSET
-#endif
+//#endif
 #define __pa(x)		((unsigned long)(x) - __pa_page_offset(x) + PHYS_OFFSET)
 #define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
-#define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x),0))
+#define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x),0)+PAGE_OFFSET)
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
diff -ruN linux-2.6.21.1.orig/include/linux/console.h linux-2.6.21.1/include/linux/console.h
--- linux-2.6.21.1.orig/include/linux/console.h	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/include/linux/console.h	2007-06-07 18:58:13.000000000 +0200
@@ -61,6 +61,7 @@
 
 extern const struct consw dummy_con;	/* dummy console buffer */
 extern const struct consw vga_con;	/* VGA text console */
+extern const struct consw ps2_con;	/* PS2 GS console */
 extern const struct consw newport_con;	/* SGI Newport console  */
 extern const struct consw prom_con;	/* SPARC PROM console */
 
diff -ruN linux-2.6.21.1.orig/Makefile linux-2.6.21.1/Makefile
--- linux-2.6.21.1.orig/Makefile	2007-04-30 17:27:20.000000000 +0200
+++ linux-2.6.21.1/Makefile	2007-06-02 22:43:18.000000000 +0200
@@ -297,7 +297,7 @@
 CFLAGS_MODULE   = $(MODFLAGS)
 AFLAGS_MODULE   = $(MODFLAGS)
 LDFLAGS_MODULE  = -r
-CFLAGS_KERNEL	=
+CFLAGS_KERNEL	= -fno-delayed-branch
 AFLAGS_KERNEL	=
 
 
Binary files linux-2.6.21.1.orig/scripts/kconfig/mconf and linux-2.6.21.1/scripts/kconfig/mconf differ
