Implement exception handling for Xen
Modified: branches/xen/reactos/boot/freeldr/freeldr/Makefile
Added: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386.h
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.c
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.h
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.c
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xencons.c
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c
Added: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenvideo.c
Modified: branches/xen/reactos/boot/freeldr/freeldr/include/machine.h
Modified: branches/xen/reactos/boot/freeldr/freeldr/machine.c

Modified: branches/xen/reactos/boot/freeldr/freeldr/Makefile
--- branches/xen/reactos/boot/freeldr/freeldr/Makefile	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/Makefile	2005-04-05 17:50:21 UTC (rev 14508)
@@ -174,6 +174,7 @@
   xencons.o \
   xenctrlif.o \
   xenmem.o \
+  xenvideo.o \
   _alloca.o # For Mingw32 builds
 
 ARCH_OBJS	= $(addprefix i386/,$(ARCH_I386_OBJS))

Added: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386.h
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386.h	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386.h	2005-04-05 17:50:21 UTC (rev 14508)
@@ -0,0 +1,47 @@
+/*
+ *  FreeLoader
+ *
+ *  Copyright (C) 2003  Eric Kohl
+ *
+ *  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 __I386_I386_H_
+#define __I386_I386_H_
+
+extern void i386DivideByZero();
+extern void i386DebugException();
+extern void i386NMIException();
+extern void i386Breakpoint();
+extern void i386Overflow();
+extern void i386BoundException();
+extern void i386InvalidOpcode();
+extern void i386FPUNotAvailable();
+extern void i386DoubleFault();
+extern void i386CoprocessorSegment();
+extern void i386InvalidTSS();
+extern void i386SegmentNotPresent();
+extern void i386StackException();
+extern void i386GeneralProtectionFault();
+extern void i386PageFault();
+extern void i386CoprocessorError();
+extern void i386AlignmentCheck();
+extern void i386MachineCheck();
+
+extern void (*i386TrapSaveDRHook)(unsigned long *DRRegs);
+
+#endif /* __I386_I386_H_ */
+
+/* EOF */
Property changes on: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/i386trap.S	2005-04-05 17:50:21 UTC (rev 14508)
@@ -26,59 +26,7 @@
 
 #define SCREEN_ATTR 0x1f			/* Bright white on blue background */
 
-.macro SAVE_CPU_REGS
-	movl	%eax,i386_EAX
-	movl	%ebx,i386_EBX
-	movl	%ecx,i386_ECX
-	movl	%edx,i386_EDX
-	movl	%esp,i386_ESP
-	movl	%ebp,i386_EBP
-	movl	%esi,i386_ESI
-	movl	%edi,i386_EDI
-	movw	%ds,%ax
-	movw	%ax,i386_DS
-	movw	%es,%ax
-	movw	%ax,i386_ES
-	movw	%fs,%ax
-	movw	%ax,i386_FS
-	movw	%gs,%ax
-	movw	%ax,i386_GS
-	movw	%ss,%ax
-	movw	%ax,i386_SS
-	popl	%eax
-	movl	%eax,i386_EIP
-	popl	%eax
-	movw	%ax,i386_CS
-	popl	%eax
-	movl	%eax,i386_EFLAGS
-	movl	%cr0,%eax
-	movl	%eax,i386_CR0
-	//movl	%cr1,%eax
-	//movl	%eax,i386_CR1
-	movl	%cr2,%eax
-	movl	%eax,i386_CR2
-	movl	%cr3,%eax
-	movl	%eax,i386_CR3
-	movl	%dr0,%eax
-	movl	%eax,i386_DR0
-	movl	%dr1,%eax
-	movl	%eax,i386_DR1
-	movl	%dr2,%eax
-	movl	%eax,i386_DR2
-	movl	%dr3,%eax
-	movl	%eax,i386_DR3
-	movl	%dr6,%eax
-	movl	%eax,i386_DR6
-	movl	%dr7,%eax
-	movl	%eax,i386_DR7
-	sgdt	i386_GDTR
-	sidt	i386_IDTR
-	sldt	i386_LDTR
-	str		i386_TR
-.endm
 
-
-
 i386ExceptionHandlerText:
 	.ascii "An error occured in FreeLoader\n"
 	.ascii VERSION
@@ -260,6 +208,10 @@
 i386_TR:
 	.word	0
 
+/* Hook to save debug registers */
+EXTERN(i386TrapSaveDRHook)
+	.long	0
+
 /* Used to store the current X and Y position on the screen */
 i386_ScreenPosX:
 	.long	0
@@ -270,8 +222,70 @@
 i386CommonExceptionHandler:
 	.code32
 
-	SAVE_CPU_REGS
+	movl	%eax,i386_EAX
+	movl	%ebx,i386_EBX
+	movl	%ecx,i386_ECX
+	movl	%edx,i386_EDX
+	movl	%esp,i386_ESP
+	movl	%ebp,i386_EBP
+	movl	%esi,i386_ESI
+	movl	%edi,i386_EDI
+	movw	%ds,%ax
+	movw	%ax,i386_DS
+	movw	%es,%ax
+	movw	%ax,i386_ES
+	movw	%fs,%ax
+	movw	%ax,i386_FS
+	movw	%gs,%ax
+	movw	%ax,i386_GS
+	movw	%ss,%ax
+	movw	%ax,i386_SS
+	popl	%eax
+	movl	%eax,i386_EIP
+	popl	%eax
+	movw	%ax,i386_CS
+	popl	%eax
+	movl	%eax,i386_EFLAGS
+	movl	%cr0,%eax
+	movl	%eax,i386_CR0
+	//movl	%cr1,%eax
+	//movl	%eax,i386_CR1
+	movl	%cr2,%eax
+	movl	%eax,i386_CR2
+	movl	%cr3,%eax
+	movl	%eax,i386_CR3
 
+/* Check for a hook to save debug regs (it's here for the benefit of Xen) */
+	movl	i386TrapSaveDRHook,%eax
+	test	%eax,%eax
+	jz	save_dr
+	
+/* Hook present, call it */
+	pushl	$i386_DR0
+	call	*%eax
+	jmp	end_save_dr
+
+save_dr:
+/* No hook present, we can save the regs ourselves */
+	movl	%dr0,%eax
+	movl	%eax,i386_DR0
+	movl	%dr1,%eax
+	movl	%eax,i386_DR1
+	movl	%dr2,%eax
+	movl	%eax,i386_DR2
+	movl	%dr3,%eax
+	movl	%eax,i386_DR3
+	movl	%dr6,%eax
+	movl	%eax,i386_DR6
+	movl	%dr7,%eax
+	movl	%eax,i386_DR7
+
+end_save_dr:
+	sgdt	i386_GDTR
+	sidt	i386_IDTR
+	sldt	i386_LDTR
+	str	i386_TR
+
 	pushl	$SCREEN_ATTR
 	call	MachVideoClearScreen
 	add	$4,%esp
@@ -444,9 +458,8 @@
 	incl	i386_ScreenPosY
 	incl	i386_ScreenPosY
 
-	cli
 i386ExceptionHandlerHang:
-	hlt
+	call	MachDie
 	jmp	i386ExceptionHandlerHang
 
 	iret

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  *  FreeLoader
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -54,6 +53,19 @@
   MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
   MachVtbl.RTCGetCurrentDateTime = PcRTCGetCurrentDateTime;
   MachVtbl.HwDetect = PcHwDetect;
+  MachVtbl.Die = PcDie;
 }
 
+VOID
+PcDie()
+{
+  while (1)
+    {
+      __asm__ __volatile__(
+        " cli\n"
+        " hlt\n"
+      );
+    }
+}
+
 /* EOF */

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.h
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.h	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machpc.h	2005-04-05 17:50:21 UTC (rev 14508)
@@ -57,6 +57,8 @@
 
 VOID PcHwDetect(VOID);
 
+VOID PcDie(VOID);
+
 #endif /* __I386_MACHPC_H_ */
 
 /* EOF */

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  *  FreeLoader
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -52,4 +51,19 @@
   MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;
   MachVtbl.RTCGetCurrentDateTime = XboxRTCGetCurrentDateTime;
   MachVtbl.HwDetect = XboxHwDetect;
+  MachVtbl.Die = XboxDie;
 }
+
+VOID
+XboxDie()
+{
+  while (1)
+    {
+      __asm__ __volatile__(
+        " cli\n"
+        " hlt\n"
+      );
+    }
+}
+
+/* EOF */

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h	2005-04-05 17:50:21 UTC (rev 14508)
@@ -60,6 +60,8 @@
 
 VOID XboxHwDetect(VOID);
 
+VOID XboxDie(VOID);
+
 #endif /* __I386_HWXBOX_H_ */
 
 /* EOF */

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -21,13 +21,13 @@
 
 #include "freeldr.h"
 #include "machxen.h"
+#include "i386.h"
 
 #include <rosxen.h>
 #include <xen.h>
 #include <hypervisor.h>
 
 BOOL XenActive = FALSE;
-int XenCtrlIfEvtchn;
 
 VOID
 XenMachInit(VOID)
@@ -57,8 +57,55 @@
   MachVtbl.DiskGetCacheableBlockCount = XenDiskGetCacheableBlockCount;
   MachVtbl.RTCGetCurrentDateTime = XenRTCGetCurrentDateTime;
   MachVtbl.HwDetect = XenHwDetect;
+  MachVtbl.Die = XenDie;
 }
 
+VOID
+XenDie()
+{
+  XenConsFlush();
+  while (1)
+    {
+      HYPERVISOR_shutdown();
+    }
+}
+
+extern void (*i386TrapSaveDRHook)(unsigned long *DRRegs);
+extern void i386Breakpoint();
+
+static trap_info_t trap_table[] = {
+        {  0, 0, FLAT_RING1_CS, (unsigned long)i386DivideByZero           },
+        {  1, 0, FLAT_RING1_CS, (unsigned long)i386DebugException         },
+        {  2, 0, FLAT_RING1_CS, (unsigned long)i386NMIException           },
+        {  3, 3, FLAT_RING1_CS, (unsigned long)i386Breakpoint             },
+        {  4, 3, FLAT_RING1_CS, (unsigned long)i386Overflow               },
+        {  5, 3, FLAT_RING1_CS, (unsigned long)i386BoundException         },
+        {  6, 0, FLAT_RING1_CS, (unsigned long)i386InvalidOpcode          },
+        {  7, 0, FLAT_RING1_CS, (unsigned long)i386FPUNotAvailable        },
+        {  8, 0, FLAT_RING1_CS, (unsigned long)i386DoubleFault            },
+        {  9, 0, FLAT_RING1_CS, (unsigned long)i386CoprocessorSegment     },
+        { 10, 0, FLAT_RING1_CS, (unsigned long)i386InvalidTSS             },
+        { 11, 0, FLAT_RING1_CS, (unsigned long)i386SegmentNotPresent      },
+        { 12, 0, FLAT_RING1_CS, (unsigned long)i386StackException         },
+        { 13, 0, FLAT_RING1_CS, (unsigned long)i386GeneralProtectionFault },
+        { 14, 0, FLAT_RING1_CS, (unsigned long)i386PageFault              },
+        { 16, 0, FLAT_RING1_CS, (unsigned long)i386CoprocessorError       },
+        { 17, 0, FLAT_RING1_CS, (unsigned long)i386AlignmentCheck         },
+        { 18, 0, FLAT_RING1_CS, (unsigned long)i386MachineCheck           },
+        {  0, 0,             0, 0                                         }
+};
+
+static void
+XenTrapSaveDR(unsigned long *DRRegs)
+{
+  unsigned Reg;
+
+  for (Reg = 0; Reg < 8; Reg++)
+    {
+      DRRegs[Reg] = HYPERVISOR_get_debugreg(Reg);
+    }
+}
+
 /* _start is the default name ld will use as the entry point.  When xen
  * loads the domain, it will start execution at the elf entry point.  */
 
@@ -95,18 +142,21 @@
   __asm__ __volatile__("mov %%eax,%%esp\n" : : "a"(NewStackPtr));
   /* Don't use stack based variables after this */
 
+  i386TrapSaveDRHook = XenTrapSaveDR;
+  HYPERVISOR_set_trap_table(trap_table);
+
   /* Start freeldr */
   XenActive = TRUE;
   BootDrive = 0x80;
   BootMain(XenStartInfo->cmd_line);
 
   /* Shouldn't get here */
-  HYPERVISOR_shutdown();
+  XenDie();
 }
 
 #define XEN_UNIMPLEMENTED(routine) \
   printf(routine " unimplemented. Shutting down\n"); \
-  HYPERVISOR_shutdown()
+  XenDie()
 
 BOOL
 XenConsKbHit()
@@ -122,12 +172,6 @@
     return 0;
   }
 
-VOID
-XenVideoClearScreen(UCHAR Attr)
-  {
-    XEN_UNIMPLEMENTED("XenVideoClearScreen");
-  }
-
 VIDEODISPLAYMODE
 XenVideoSetDisplayMode(char *DisplayMode, BOOL Init)
   {
@@ -161,12 +205,6 @@
   }
 
 VOID
-XenVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
-  {
-    XEN_UNIMPLEMENTED("XenVideoPutChar");
-  }
-
-VOID
 XenVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
   {
     XEN_UNIMPLEMENTED("XenVideoCopyOffScreenBufferToVRAM");

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h	2005-04-05 17:50:21 UTC (rev 14508)
@@ -45,6 +45,7 @@
 VOID XenConsPutChar(int Ch);
 BOOL XenConsKbHit();
 int XenConsGetCh();
+VOID XenConsFlush();
 
 VOID XenVideoClearScreen(UCHAR Attr);
 VIDEODISPLAYMODE XenVideoSetDisplayMode(char *DisplayMode, BOOL Init);
@@ -71,6 +72,8 @@
 
 VOID XenHwDetect(VOID);
 
+VOID XenDie(VOID);
+
 #endif /* __I386_MACHXEN_H_ */
 
 /* EOF */

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xencons.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xencons.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xencons.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -37,8 +37,8 @@
 static char OutputBuffer[OUTPUT_BUFFER_SIZE];
 static unsigned OutputPtr = 0;
 
-static void
-FlushOutput()
+VOID
+XenConsFlush()
 {
   ctrl_msg_t Msg;
 
@@ -69,7 +69,7 @@
 {
   if (OUTPUT_BUFFER_SIZE <= OutputPtr)
     {
-      FlushOutput();
+      XenConsFlush();
     }
   OutputBuffer[OutputPtr++] = Ch;
 }
@@ -81,7 +81,7 @@
     {
       PutCharInBuffer('\r');
       PutCharInBuffer('\n');
-      FlushOutput();
+      XenConsFlush();
     }
   else
     {

Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -204,7 +204,7 @@
       if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
         {
           HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-          HYPERVISOR_shutdown();
+          XenDie();
         }
     }
 
@@ -217,7 +217,7 @@
   if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
     {
       HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-      HYPERVISOR_shutdown();
+      XenDie();
     }
   XenPageDir = (PPDE) HighAddr;
 
@@ -231,7 +231,7 @@
   if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
     {
       HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-      HYPERVISOR_shutdown();
+      XenDie();
     }
 
   /* Map the page tables near the top of mem */
@@ -247,7 +247,7 @@
       if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
         {
           HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-          HYPERVISOR_shutdown();
+          XenDie();
         }
     }
 
@@ -276,7 +276,7 @@
           if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
             {
               HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-              HYPERVISOR_shutdown();
+              XenDie();
             }
         }
     }
@@ -296,7 +296,7 @@
   if (0 != HYPERVISOR_mmu_update(&MmuReq, 1, NULL))
     {
       HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg);
-      HYPERVISOR_shutdown();
+      XenDie();
     }
 }
 

Added: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenvideo.c
--- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenvideo.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenvideo.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -0,0 +1,105 @@
+/*
+ *  FreeLoader
+ *
+ *  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.
+ */
+/*
+ * Xen virtualization of the console isn't that great, it doesn't properly
+ * virtualize full-screen access. We simulate it by sending ANSI control
+ * codes and assume a display size of 80x25. This should be enough for proper
+ * display on e.g. linux consoles and xterms.
+ */
+
+#include "freeldr.h"
+#include "machxen.h"
+
+#define ROWS 25
+#define COLS 80
+
+static unsigned CurrentX = (unsigned) -1;
+static unsigned CurrentY = (unsigned) -1;
+static UCHAR CurrentAttr = 0x07;
+
+
+static VOID
+AnsiMoveToPos(unsigned X, unsigned Y)
+{
+  CurrentX = X;
+  CurrentY = Y;
+  printf("\033[%d;%dH", Y + 1, X + 1);
+}
+
+static VOID
+AnsiSetAttr(UCHAR Attr)
+{
+  /* Convert color from BIOS (RGB) to ANSI (BGR) */
+  static UCHAR ConvertColor[] =
+    { 0x00, 0x04, 0x02, 0x06, 0x01, 0x05, 0x03, 0x07 };
+  char Bright[3];
+
+  CurrentAttr = Attr;
+  /* Check for bright foreground */
+  if (0 != (Attr & 0x08))
+    {
+      strcpy(Bright, "1;");
+    }
+  else
+    {
+      Bright[0] = '\0';
+    }
+  printf("\033[%s3%d;4%dm", Bright, ConvertColor[Attr & 0x07],
+         ConvertColor[(Attr >> 4) & 0x07]);
+}
+
+static VOID
+AnsiClearScreen()
+{
+  printf("\033[H\033[J\n");
+}
+
+VOID
+XenVideoClearScreen(UCHAR Attr)
+{
+  if (Attr != CurrentAttr)
+    {
+      AnsiSetAttr(Attr);
+    }
+  AnsiClearScreen();
+}
+
+VOID
+XenVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
+{
+  /* Don't write outside the screen or on the bottom-right position,
+     it might trigger a scroll operation */
+  if (COLS <= X || ROWS <= Y
+      || (X == COLS - 1 && Y == ROWS - 1))
+    {
+      return;
+    }
+
+  if (X != CurrentX || Y != CurrentY)
+    {
+      AnsiMoveToPos(X, Y);
+    }
+  if (Attr != CurrentAttr)
+    {
+      AnsiSetAttr(Attr);
+    }
+  XenConsPutChar(Ch);
+  CurrentX++;
+}
+
+/* EOF */
Property changes on: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenvideo.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/xen/reactos/boot/freeldr/freeldr/include/machine.h
--- branches/xen/reactos/boot/freeldr/freeldr/include/machine.h	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/include/machine.h	2005-04-05 17:50:21 UTC (rev 14508)
@@ -64,6 +64,8 @@
   VOID (*RTCGetCurrentDateTime)(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second);
 
   VOID (*HwDetect)(VOID);
+
+  VOID (*Die)(VOID);
 } MACHVTBL, *PMACHVTBL;
 
 VOID MachInit(VOID);
@@ -93,6 +95,7 @@
 #define MachDiskGetCacheableBlockCount(Drive)	MachVtbl.DiskGetCacheableBlockCount(Drive)
 #define MachRTCGetCurrentDateTime(Y, Mo, D, H, Mi, S)	MachVtbl.RTCGetCurrentDateTime((Y), (Mo), (D), (H), (Mi), (S));
 #define MachHwDetect()				MachVtbl.HwDetect()
+#define MachDie()				MachVtbl.Die()
 
 #endif /* __MACHINE_H_ */
 

Modified: branches/xen/reactos/boot/freeldr/freeldr/machine.c
--- branches/xen/reactos/boot/freeldr/freeldr/machine.c	2005-04-05 17:22:02 UTC (rev 14507)
+++ branches/xen/reactos/boot/freeldr/freeldr/machine.c	2005-04-05 17:50:21 UTC (rev 14508)
@@ -43,6 +43,7 @@
 #undef MachDiskGetCacheableBlockCount
 #undef MachRTCGetCurrentDateTime
 #undef MachHwDetect
+#undef MachDie
 
 MACHVTBL MachVtbl;
 
@@ -184,4 +185,10 @@
   MachVtbl.HwDetect();
 }
 
+VOID
+MachDie(VOID)
+{
+  MachVtbl.Die();
+}
+
 /* EOF */