Merge 14269:14454 from trunk.
Modified: branches/cache_manager_rewrite/reactos/apps/testsets/loadlib/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/Makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ping/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/partinfo/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/partinfo/partinfo.c
Modified: branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/pnpdump.c
Modified: branches/cache_manager_rewrite/reactos/apps/utils/ps/makefile
Modified: branches/cache_manager_rewrite/reactos/apps/utils/sc/makefile
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/Makefile
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile
Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.i386
Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.powerpc
Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/ofwboot.s
Added: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/powerpc/
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.c
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/libgcc2.c
Added: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/powerpc.h
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/mem.h
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/print.c
Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/stdlib.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/circularbuffer.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/devctrl.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/legacy.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/misc.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/pnp.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/rw.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/serial.c
Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/serial.h
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/create.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/fsctrl.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/npfs.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/npfs.h
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/rw.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/cleanup.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/close.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/fcb.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/fsctl.c
Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/vfat.h
Modified: branches/cache_manager_rewrite/reactos/drivers/lib/ip/network/ip.c
Modified: branches/cache_manager_rewrite/reactos/drivers/net/ndis/ndis/protocol.c
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/include/dispatch.h
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/include/ip.h
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/include/ticonsts.h
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/tcpip/dispatch.c
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/tcpip/iinfo.c
Modified: branches/cache_manager_rewrite/reactos/drivers/net/tcpip/tcpip/main.c
Modified: branches/cache_manager_rewrite/reactos/drivers/video/videoprt/dispatch.c
Modified: branches/cache_manager_rewrite/reactos/drivers/video/videoprt/interrupt.c
Modified: branches/cache_manager_rewrite/reactos/drivers/video/videoprt/resource.c
Modified: branches/cache_manager_rewrite/reactos/drivers/video/videoprt/videoprt.h
Modified: branches/cache_manager_rewrite/reactos/hal/hal/hal.c
Modified: branches/cache_manager_rewrite/reactos/hal/hal/hal.def
Modified: branches/cache_manager_rewrite/reactos/hal/halx86/generic/spinlock.c
Deleted: branches/cache_manager_rewrite/reactos/include/WinDNS.h
Deleted: branches/cache_manager_rewrite/reactos/include/WinError.h
Deleted: branches/cache_manager_rewrite/reactos/include/WinFax.h
Deleted: branches/cache_manager_rewrite/reactos/include/WinSCard.h
Deleted: branches/cache_manager_rewrite/reactos/include/WinSmCrd.h
Deleted: branches/cache_manager_rewrite/reactos/include/WinWlx.h
Deleted: branches/cache_manager_rewrite/reactos/include/aclui.h
Deleted: branches/cache_manager_rewrite/reactos/include/ascii.h
Deleted: branches/cache_manager_rewrite/reactos/include/coff.h
Modified: branches/cache_manager_rewrite/reactos/include/ddk/mmfuncs.h
Modified: branches/cache_manager_rewrite/reactos/include/funcs.h
Deleted: branches/cache_manager_rewrite/reactos/include/icmpapi.h
Modified: branches/cache_manager_rewrite/reactos/include/ntos/rtl.h
Modified: branches/cache_manager_rewrite/reactos/include/pe.h
Modified: branches/cache_manager_rewrite/reactos/include/pseh/excpt.h
Modified: branches/cache_manager_rewrite/reactos/include/pseh/framebased/internal.h
Modified: branches/cache_manager_rewrite/reactos/include/pseh/framebased.h
Added: branches/cache_manager_rewrite/reactos/include/pseh/native.h
Modified: branches/cache_manager_rewrite/reactos/include/pseh/setjmp.h
Modified: branches/cache_manager_rewrite/reactos/include/pseh.h
Deleted: branches/cache_manager_rewrite/reactos/include/sockets.h
Modified: branches/cache_manager_rewrite/reactos/include/tcpioctl.h
Deleted: branches/cache_manager_rewrite/reactos/include/wine/cpl.h
Deleted: branches/cache_manager_rewrite/reactos/include/wine/fci.h
Deleted: branches/cache_manager_rewrite/reactos/include/wine/fdi.h
Deleted: branches/cache_manager_rewrite/reactos/include/wine/heap.h
Deleted: branches/cache_manager_rewrite/reactos/include/wine/ver.h
Modified: branches/cache_manager_rewrite/reactos/lib/aclui/aclui.rc
Added: branches/cache_manager_rewrite/reactos/lib/aclui/aclui_Sv.rc
Modified: branches/cache_manager_rewrite/reactos/lib/advapi32/advapi32.def
Modified: branches/cache_manager_rewrite/reactos/lib/advapi32/crypt/crypt.c
Modified: branches/cache_manager_rewrite/reactos/lib/advapi32/misc/sysfunc.c
Added: branches/cache_manager_rewrite/reactos/lib/comctl32/comctl_Sv.rc
Modified: branches/cache_manager_rewrite/reactos/lib/comctl32/rsrc.rc
Deleted: branches/cache_manager_rewrite/reactos/lib/commctrl/
Deleted: branches/cache_manager_rewrite/reactos/lib/coredll/
Modified: branches/cache_manager_rewrite/reactos/lib/cpl/desk/de.rc
Modified: branches/cache_manager_rewrite/reactos/lib/cpl/desk/en.rc
Modified: branches/cache_manager_rewrite/reactos/lib/cpl/desk/resource.h
Modified: branches/cache_manager_rewrite/reactos/lib/cpl/desk/settings.c
Added: branches/cache_manager_rewrite/reactos/lib/cpl/sysdm/dk.rc
Added: branches/cache_manager_rewrite/reactos/lib/cpl/timedate/Sv.rc
Modified: branches/cache_manager_rewrite/reactos/lib/cpl/timedate/timedate.rc
Modified: branches/cache_manager_rewrite/reactos/lib/crt/except/matherr.c
Modified: branches/cache_manager_rewrite/reactos/lib/crt/float/fpecode.c
[truncated at 100 lines; 180 more skipped]
Modified: branches/cache_manager_rewrite/reactos/apps/testsets/loadlib/makefile
--- branches/cache_manager_rewrite/reactos/apps/testsets/loadlib/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/testsets/loadlib/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -11,7 +11,7 @@
 
 TARGET_NAME = loadlib
 
-TARGET_CFLAGS = -Wall -Werror -D_USE_W32API -DUNICODE -D_UNICODE
+TARGET_CFLAGS = -Wall -Werror -D__USE_W32API -DUNICODE -D_UNICODE
 
 TARGET_SDKLIBS = kernel32.a ntdll.a 
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/Makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/Makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/Makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -9,7 +9,7 @@
 
 # Console system utilities
 # cabman cat net objdir partinfo pice ps sc stats
-UTIL_APPS = cat objdir partinfo pnpdump sc shutdown stats tickcount ps
+UTIL_APPS = cat objdir pnpdump sc shutdown stats tickcount ps
 
 UTIL_NET_APPS = arp finger ftp ipconfig netstat ping route telnet whois
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -8,6 +8,8 @@
 
 TARGET_INSTALLDIR = system32
 
+TARGET_CFLAGS = -D__USE_W32API
+
 TARGET_SDKLIBS = ws2_32.a iphlpapi.a
 # ntdll.a
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ping/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/net/ping/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/net/ping/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -8,7 +8,7 @@
 
 TARGET_INSTALLDIR = system32
 
-TARGET_CFLAGS = -D__USE_W32_SOCKETS
+TARGET_CFLAGS = -D__USE_W32API -D__USE_W32_SOCKETS
 
 TARGET_SDKLIBS = ws2_32.a
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/partinfo/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/partinfo/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/partinfo/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -10,7 +10,7 @@
 
 TARGET_NAME = partinfo
 
-TARGET_CFLAGS = -Wall -Werror -Wno-format
+TARGET_CFLAGS = -D__USE_W32API -Wall -Werror -Wno-format
 
 TARGET_SDKLIBS = ntdll.a kernel32.a
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/partinfo/partinfo.c
--- branches/cache_manager_rewrite/reactos/apps/utils/partinfo/partinfo.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/partinfo/partinfo.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -8,10 +8,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <ddk/ntddk.h>
+
 //#define DUMP_DATA
 #define DUMP_SIZE_INFO
+#define UNICODE
 
-
 #ifdef DUMP_DATA
 void HexDump(char *buffer, ULONG size)
 {

Modified: branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -10,7 +10,7 @@
 
 TARGET_NAME = pnpdump
 
-TARGET_CFLAGS = -Wall -Werror
+TARGET_CFLAGS = -D__USE_W32API -Wall -Werror
 
 TARGET_SDKLIBS = ntdll.a kernel32.a
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/pnpdump.c
--- branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/pnpdump.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/pnpdump/pnpdump.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -8,6 +8,8 @@
 #include <stdlib.h>
 #include <conio.h>
 
+#include <ddk/ntddk.h>
+
 #include <pshpack1.h>
 
 typedef struct _CM_PNP_BIOS_DEVICE_NODE

Modified: branches/cache_manager_rewrite/reactos/apps/utils/ps/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/ps/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/ps/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -10,7 +10,7 @@
 
 TARGET_NAME = ps
 
-TARGET_CFLAGS = -DANONYMOUSUNIONS -Werror -Wall
+TARGET_CFLAGS = -D__USE_W32API -DANONYMOUSUNIONS -Werror -Wall
 
 TARGET_SDKLIBS = ntdll.a kernel32.a user32.a
 

Modified: branches/cache_manager_rewrite/reactos/apps/utils/sc/makefile
--- branches/cache_manager_rewrite/reactos/apps/utils/sc/makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/apps/utils/sc/makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -13,7 +13,7 @@
 
 TARGET_NAME = sc
 
-TARGET_CFLAGS = -DDBG -Werror -Wall
+TARGET_CFLAGS = -D__USE_W32API -DDBG -Werror -Wall
 
 TARGET_SDKLIBS = kernel32.a ntdll.a advapi32.a
 

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/Makefile
--- branches/cache_manager_rewrite/reactos/boot/freeldr/Makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/Makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -29,7 +29,7 @@
 	$(MAKE) -C fdebug
 
 test:
-	
+
 clean:
 	$(MAKE) -C bootsect clean
 	$(MAKE) -C freeldr clean
@@ -38,6 +38,7 @@
 	$(MAKE) -C tools clean
 
 bootcd:
+ifeq ($(ARCH),i386)
 	$(CP) bootsect/isoboot.bin ${BOOTCD_DIR}/../isoboot.bin
 	$(CP) bootsect/dosmbr.bin ${BOOTCD_DIR}/loader/dosmbr.bin
 	$(CP) bootsect/ext2.bin ${BOOTCD_DIR}/loader/ext2.bin
@@ -46,5 +47,7 @@
 	$(CP) bootsect/isoboot.bin ${BOOTCD_DIR}/loader/isoboot.bin
 	$(CP) freeldr/freeldr.sys ${BOOTCD_DIR}/loader/freeldr.sys
 	$(CP) freeldr/setupldr.sys ${BOOTCD_DIR}/loader/setupldr.sys
+endif
 
 .PHONY : clean
+

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile
--- branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile	2005-05-16 19:34:42 UTC (rev 15351)
@@ -25,56 +25,8 @@
 
 .PHONY : clean bootcd
 
-all: $(BIN2C) dosmbr.bin fat.bin fat32.bin isoboot.bin ext2.bin
-
-
-$(BIN2C) :
-	@$(MAKE) --no-print-directory -C $(FREELDR_TOOLS_PATH)
-
-dosmbr.bin : dosmbr.asm
-	@echo freeldr: Assembling dosmbr
-	@$(NASM_CMD) $(NFLAGS) -o dosmbr.bin -f bin dosmbr.asm
-
-fat.bin : fat.asm $(BIN2C)
-	@echo freeldr: Assembling fat
-	@$(NASM_CMD) $(NFLAGS) -o fat.bin -f bin fat.asm
-	@$(BIN2C) fat.bin fat.h fat_data
-
-
-fat32.bin : fat32.asm $(BIN2C)
-	@echo freeldr: Assembling fat32
-	@$(NASM_CMD) $(NFLAGS) -o fat32.bin -f bin fat32.asm
-	@$(BIN2C) fat32.bin fat32.h fat32_data
-
-isoboot.bin : isoboot.asm
-	@echo freeldr: Assembling isoboot
-	@$(NASM_CMD) $(NFLAGS) -o isoboot.bin -f bin isoboot.asm
-
-ext2.bin : ext2.asm
-	@echo freeldr: Assembling ext2
-	@$(NASM_CMD) $(NFLAGS) -o ext2.bin -f bin ext2.asm
-	@$(BIN2C) ext2.bin ext2.h ext2_data
-
-
-.PHONY : bootcd
-bootcd: bootcd_dirs isoboot.bin
-	$(CP) isoboot.bin $(BOOTCD_DIR)
-	$(CP) dosmbr.bin $(BOOTCD_DIR)/disk/loader
-	$(CP) ext2.bin $(BOOTCD_DIR)/disk/loader
-	$(CP) fat.bin $(BOOTCD_DIR)/disk/loader
-	$(CP) fat32.bin $(BOOTCD_DIR)/disk/loader
-	$(CP) isoboot.bin $(BOOTCD_DIR)/disk/loader
-
-.PHONY : bootcd_dirs
-bootcd_dirs:
-	$(MKDIR) $(BOOTCD_DIR)
-	$(MKDIR) $(BOOTCD_DIR)/disk
-	$(MKDIR) $(BOOTCD_DIR)/disk/reactos
-	$(MKDIR) $(BOOTCD_DIR)/disk/install
-	$(MKDIR) $(BOOTCD_DIR)/disk/bootdisk
-	$(MKDIR) $(BOOTCD_DIR)/disk/loader
-
-clean:
-	@-$(RM) *.bin
-	@-$(RM) *.h
-	@echo freeldr: Clean ALL done.
+ifeq ($(ARCH),powerpc)
+include Makefile.powerpc
+else
+include Makefile.i386
+endif

Copied: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.i386 (from rev 14454, trunk/reactos/boot/freeldr/bootsect/Makefile.i386)

Copied: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.powerpc (from rev 14454, trunk/reactos/boot/freeldr/bootsect/Makefile.powerpc)

Copied: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/ofwboot.s (from rev 14454, trunk/reactos/boot/freeldr/bootsect/ofwboot.s)

Copied: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/powerpc (from rev 14454, trunk/reactos/boot/freeldr/freeldr/arch/powerpc)

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.c
--- branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -21,7 +21,7 @@
  * Limitations:
  * - No support for compressed files.
  * - No attribute list support.
- * - May crash on currupted filesystem.
+ * - May crash on corrupted filesystem.
  */
 
 #include <freeldr.h>

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/libgcc2.c
--- branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/libgcc2.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/libgcc2.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -38,6 +38,8 @@
  */
 #ifdef __i386__
 #include "i386.h"
+#elif defined(_M_PPC)
+#include "powerpc.h"
 #endif
 #define L_clz
 #define L_udivdi3

Copied: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/math/powerpc.h (from rev 14454, trunk/reactos/boot/freeldr/freeldr/math/powerpc.h)

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/mem.h
--- branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/mem.h	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/mem.h	2005-05-16 19:34:42 UTC (rev 15351)
@@ -22,11 +22,11 @@
 #define __MEM_H
 
 
-#ifdef __i386__
+#if  defined(__i386__) || defined(_PPC_)
 
 #define MM_PAGE_SIZE	4096
 
-#endif // defined __i386__
+#endif // defined __i386__ or _PPC_
 
 typedef struct
 {

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/print.c
--- branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/print.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/print.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -20,6 +20,7 @@
 #include <freeldr.h>
 #include <machine.h>
 #include <rtl.h>
+#include <stdarg.h>
 
 /*
  * print() - prints unformatted text to stdout
@@ -38,12 +39,11 @@
  */
 void printf(char *format, ... )
 {
-	int *dataptr = (int *)(void *)&format;
+	va_list ap;
+	va_start(ap,format);
 	char c, *ptr, str[16];
 	int ll;
 
-	dataptr++;
-
 	while ((c = *(format++)))
 	{
 		if (c != '%')
@@ -66,11 +66,11 @@
 			case 'd': case 'u': case 'x':
 				if (ll)
 				{
-					*convert_i64_to_ascii(str, c, *((unsigned long long *) dataptr++)) = 0;
+					*convert_i64_to_ascii(str, c, va_arg(ap, unsigned long long)) = 0;
 				}
 				else
 				{
-					*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
+					*convert_to_ascii(str, c, va_arg(ap, unsigned long)) = 0;
 				}
 
 				ptr = str;
@@ -81,10 +81,10 @@
 				}
 				break;
 
-			case 'c': MachConsPutChar((*(dataptr++))&0xff); break;
+			case 'c': MachConsPutChar((va_arg(ap,int))&0xff); break;
 
 			case 's':
-				ptr = (char *)(*(dataptr++));
+				ptr = va_arg(ap,char *);
 
 				while ((c = *(ptr++)))
 				{
@@ -100,16 +100,18 @@
 			}
 		}
 	}
+
+	va_end(ap);
 }
 
 void sprintf(char *buffer, char *format, ... )
 {
-	int *dataptr = (int *)(void *)&format;
+	va_list ap;
 	char c, *ptr, str[16];
 	char *p = buffer;
 	int ll;
 
-	dataptr++;
+	va_start(ap,format);
 
 	while ((c = *(format++)))
 	{
@@ -134,11 +136,11 @@
 			case 'd': case 'u': case 'x':
 				if (ll)
 				{
-					*convert_i64_to_ascii(str, c, *((unsigned long long*) dataptr++)) = 0;
+					*convert_i64_to_ascii(str, c, va_arg(ap, unsigned long long)) = 0;
 				}
 				else
 				{
-					*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
+					*convert_to_ascii(str, c, va_arg(ap, unsigned long)) = 0;
 				}
 					
 				ptr = str;
@@ -151,12 +153,12 @@
 				break;
 
 			case 'c':
-				*p = (*(dataptr++))&0xff;
+				*p = va_arg(ap,int)&0xff;
 				p++;
 				break;
 
 			case 's':
-				ptr = (char *)(*(dataptr++));
+				ptr = va_arg(ap,char *);
 
 				while ((c = *(ptr++)))
 				{
@@ -174,5 +176,6 @@
 			}
 		}
 	}
+	va_end(ap);
 	*p=0;
 }

Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/stdlib.c
--- branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/stdlib.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/stdlib.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -17,16 +17,15 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-
 /*
  * convert_to_ascii() - converts a number to it's ascii equivalent
  * from:
  *  GRUB  --  GRand Unified Bootloader
  *  Copyright (C) 1996   Erich Boleyn  <erich@uruk.org>
  */
-char *convert_to_ascii(char *buf, int c, ...)
+char *convert_to_ascii(char *buf, int c, int num)
 {
-  unsigned long num = *((&c) + 1), mult = 10;
+  unsigned long mult = 10;
   char *ptr = buf;
 
   if (c == 'x')
@@ -63,9 +62,8 @@
   return ptr;
 }
 
-char *convert_i64_to_ascii(char *buf, int c, ...)
+char *convert_i64_to_ascii(char *buf, int c, unsigned long long num)
 {
-  unsigned long long num = *(long long*)((&c) + 1);
   int mult = 10;
   char *ptr = buf;
 

Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/circularbuffer.c
--- branches/cache_manager_rewrite/reactos/drivers/dd/serial/circularbuffer.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/drivers/dd/serial/circularbuffer.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -8,7 +8,7 @@
  * PROGRAMMERS:     HervÚ Poussineau (poussine@freesurf.fr)
  */
 
-//#define NDEBUG
+#define NDEBUG
 #include "serial.h"
 
 NTSTATUS
@@ -16,7 +16,8 @@
 	IN PCIRCULAR_BUFFER pBuffer,
 	IN ULONG BufferSize)
 {
-	pBuffer->Buffer = ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG);
+	DPRINT("Serial: InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
+	pBuffer->Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG);
 	if (!pBuffer->Buffer)
 		return STATUS_INSUFFICIENT_RESOURCES;
 	pBuffer->Length = BufferSize;
@@ -28,6 +29,7 @@
 FreeCircularBuffer(
 	IN PCIRCULAR_BUFFER pBuffer)
 {
+	DPRINT("Serial: FreeCircularBuffer(pBuffer %p)\n", pBuffer);
 	ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG);
 	return STATUS_SUCCESS;
 }
@@ -36,6 +38,7 @@
 IsCircularBufferEmpty(
 	IN PCIRCULAR_BUFFER pBuffer)
 {
+	DPRINT("Serial: IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
 	return (pBuffer->ReadPosition == pBuffer->WritePosition);
 }
 
@@ -44,6 +47,7 @@
 	IN PCIRCULAR_BUFFER pBuffer,
 	IN UCHAR Entry)
 {
+	DPRINT("Serial: PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
 	ASSERT(pBuffer->Length);
 	ULONG NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
 	if (NextPosition == pBuffer->ReadPosition)
@@ -58,6 +62,7 @@
 	IN PCIRCULAR_BUFFER pBuffer,
 	OUT PUCHAR Entry)
 {
+	DPRINT("Serial: PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
 	ASSERT(pBuffer->Length);
 	if (IsCircularBufferEmpty(pBuffer))
 		return STATUS_ARRAY_BOUNDS_EXCEEDED;
@@ -65,3 +70,27 @@
 	pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
 	return STATUS_SUCCESS;
 }
+
+NTSTATUS
+IncreaseCircularBufferSize(
+	IN PCIRCULAR_BUFFER pBuffer,
+	IN ULONG NewBufferSize)
+{
+	PUCHAR NewBuffer;
+	
+	DPRINT("Serial: IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
+	ASSERT(pBuffer->Length);
+	if (pBuffer->Length > NewBufferSize)
+		return STATUS_INVALID_PARAMETER;
+	else if (pBuffer->Length == NewBufferSize)
+		return STATUS_SUCCESS;
+	
+	NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG);
+	if (!NewBuffer)
+		return STATUS_INSUFFICIENT_RESOURCES;
+	RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR));
+	ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG);
+	pBuffer->Buffer = NewBuffer;
+	pBuffer->Length = NewBufferSize;
+	return STATUS_SUCCESS;
+}

Modified: branches/cache_manager_rewrite/reactos/drivers/dd/serial/devctrl.c
--- branches/cache_manager_rewrite/reactos/drivers/dd/serial/devctrl.c	2005-05-16 19:28:18 UTC (rev 15350)
+++ branches/cache_manager_rewrite/reactos/drivers/dd/serial/devctrl.c	2005-05-16 19:34:42 UTC (rev 15351)
@@ -7,11 +7,42 @@
  * 
  * PROGRAMMERS:     HervÚ Poussineau (poussine@freesurf.fr)
  */
-/* FIXME: call IoAcquireRemoveLock/IoReleaseRemoveLock around each I/O operation */
 
 #define NDEBUG
 #include "serial.h"
 
+#define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
+
+static VOID
+SerialGetUserBuffers(
+	IN PIRP Irp,
+	IN ULONG IoControlCode,
+	OUT PVOID* BufferIn,
+	OUT PVOID* BufferOut)
+{
+   ASSERT(Irp);
+   ASSERT(BufferIn);
+   ASSERT(BufferOut);
+   
+	switch (IO_METHOD_FROM_CTL_CODE(IoControlCode))
+	{
+		case METHOD_BUFFERED:
+			*BufferIn = *BufferOut = Irp->AssociatedIrp.SystemBuffer;
+			return;
+		case METHOD_IN_DIRECT:
+		case METHOD_OUT_DIRECT:
+			*BufferIn = Irp->AssociatedIrp.SystemBuffer;
+			*BufferOut = MmGetSystemAddressForMdl(Irp->MdlAddress);
+			return;
+		case METHOD_NEITHER:
+			*BufferIn = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.Type3InputBuffer;
+			*BufferOut = Irp->UserBuffer;
+			return;
+	}
+	
+	/* Should never happen */
+}
+
 NTSTATUS STDCALL
 SerialSetBaudRate(
 	IN PSERIAL_DEVICE_EXTENSION DeviceExtension,
@@ -60,16 +91,13 @@
 		{
 			UCHAR Lcr;
 			DPRINT("Serial: SerialSetBaudRate(COM%lu, %lu Bauds)\n", DeviceExtension->ComPort, BaudRate);
-			/* FIXME: update DeviceExtension->LowerDevice when modifying LCR? */
 			/* Set Bit 7 of LCR to expose baud registers */
 			Lcr = READ_PORT_UCHAR(SER_LCR(ComPortBase));
-			Lcr |= SR_LCR_DLAB;
-			WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr);
+			WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr | SR_LCR_DLAB);
 			/* Write the baud rate */
 			WRITE_PORT_UCHAR(SER_DLL(ComPortBase), divisor & 0xff);
 			WRITE_PORT_UCHAR(SER_DLM(ComPortBase), divisor >> 8);
 			/* Switch back to normal registers */
-			Lcr ^= SR_LCR_DLAB;
 			WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr);
 			
 			IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
@@ -77,7 +105,7 @@
 	}
 	
 	if (NT_SUCCESS(Status))
-		DeviceExtension->BaudRate = NewBaudRate;
+		DeviceExtension->BaudRate = BaudRate;
 	return Status;
 }
 
@@ -190,22 +218,30 @@
 	pCommProp->ServiceMask = SERIAL_SP_SERIALCOMM;
 	pCommProp->MaxTxQueue = pCommProp->CurrentTxQueue = DeviceExtension->OutputBuffer.Length - 1;
 	pCommProp->MaxRxQueue = pCommProp->CurrentRxQueue = DeviceExtension->InputBuffer.Length - 1;
-	pCommProp->MaxBaud = SERIAL_BAUD_115200;
 	pCommProp->ProvSubType = 1; // PST_RS232;
-	/* FIXME: ProvCapabilities may be related to Uart type */
 	pCommProp->ProvCapabilities = SERIAL_PCF_DTRDSR | SERIAL_PCF_INTTIMEOUTS | SERIAL_PCF_PARITY_CHECK
 		| SERIAL_PCF_RTSCTS | SERIAL_PCF_SETXCHAR | SERIAL_PCF_SPECIALCHARS | SERIAL_PCF_TOTALTIMEOUTS
 		| SERIAL_PCF_XONXOFF;
-	/* FIXME: SettableParams may be related to Uart type */
 	pCommProp->SettableParams = SERIAL_SP_BAUD | SERIAL_SP_DATABITS | SERIAL_SP_HANDSHAKING
 		| SERIAL_SP_PARITY | SERIAL_SP_PARITY_CHECK | SERIAL_SP_STOPBITS;
-	/* FIXME: SettableBaud may be related to Uart type */
+	
+	/* SettableBaud is related to Uart type */
 	pCommProp->SettableBaud = SERIAL_BAUD_075 | SERIAL_BAUD_110 | SERIAL_BAUD_134_5
 		| SERIAL_BAUD_150 | SERIAL_BAUD_300 | SERIAL_BAUD_600 | SERIAL_BAUD_1200
 		| SERIAL_BAUD_1800 | SERIAL_BAUD_2400 | SERIAL_BAUD_4800 | SERIAL_BAUD_7200
-		| SERIAL_BAUD_9600 | SERIAL_BAUD_14400 | SERIAL_BAUD_19200 | SERIAL_BAUD_38400
-		| SERIAL_BAUD_56K | SERIAL_BAUD_57600 | SERIAL_BAUD_115200 | SERIAL_BAUD_128K
-		| SERIAL_BAUD_USER;
+		| SERIAL_BAUD_9600 | SERIAL_BAUD_USER;
+	pCommProp->MaxBaud = SERIAL_BAUD_9600;
+	if (DeviceExtension->UartType >= Uart16450)
+	{
+		pCommProp->SettableBaud |= SERIAL_BAUD_14400 | SERIAL_BAUD_19200 | SERIAL_BAUD_38400;
+		pCommProp->MaxBaud = SERIAL_BAUD_38400;
+	}
+	if (DeviceExtension->UartType >= Uart16550)
+	{
+		pCommProp->SettableBaud |= SERIAL_BAUD_56K | SERIAL_BAUD_57600 | SERIAL_BAUD_115200 | SERIAL_BAUD_128K;
+		pCommProp->MaxBaud = SERIAL_BAUD_115200;
+	}
+	
 	pCommProp->SettableData = SERIAL_DATABITS_5 | SERIAL_DATABITS_6 | SERIAL_DATABITS_7 | SERIAL_DATABITS_8;
 	pCommProp->SettableStopParity = SERIAL_STOPBITS_10 | SERIAL_STOPBITS_15 | SERIAL_STOPBITS_20
 		| SERIAL_PARITY_NONE | SERIAL_PARITY_ODD | SERIAL_PARITY_EVEN | SERIAL_PARITY_MARK | SERIAL_PARITY_SPACE;
@@ -213,33 +249,61 @@
 	return STATUS_SUCCESS;
 }
 
+NTSTATUS
+SerialGetCommStatus(
+	OUT PSERIAL_STATUS pSerialStatus,
+	IN PSERIAL_DEVICE_EXTENSION DeviceExtension)
+{
+	KIRQL Irql;
+	
+	RtlZeroMemory(pSerialStatus, sizeof(SERIAL_STATUS));
+	
+	pSerialStatus->Errors = 0; /* FIXME */
+	pSerialStatus->HoldReasons = 0; /* FIXME */
+	
+	KeAcquireSpinLock(&DeviceExtension->InputBufferLock, &Irql);
+	pSerialStatus->AmountInInQueue = (DeviceExtension->InputBuffer.WritePosition + DeviceExtension->InputBuffer.Length
+		- DeviceExtension->InputBuffer.ReadPosition) % DeviceExtension->InputBuffer.Length;
+	KeReleaseSpinLock(&DeviceExtension->InputBufferLock, Irql);
+	
+	KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql);
+	pSerialStatus->AmountInOutQueue = (DeviceExtension->OutputBuffer.WritePosition + DeviceExtension->OutputBuffer.Length
+		- DeviceExtension->OutputBuffer.ReadPosition) % DeviceExtension->OutputBuffer.Length;
+	KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql);
+	
+	pSerialStatus->EofReceived = FALSE; /* always FALSE */
+	pSerialStatus->WaitForImmediate = FALSE; /* always FALSE */
+	
+	return STATUS_SUCCESS;
+}
+
 NTSTATUS STDCALL
 SerialDeviceControl(
 	IN PDEVICE_OBJECT DeviceObject,
 	IN PIRP Irp)
 {
 	PIO_STACK_LOCATION Stack;
+	ULONG IoControlCode;
 	PSERIAL_DEVICE_EXTENSION DeviceExtension;
 	ULONG LengthIn, LengthOut;
 	ULONG Information = 0;
-	PUCHAR Buffer;
+	PVOID BufferIn, BufferOut;
 	PUCHAR ComPortBase;
 	NTSTATUS Status;
 	
 	DPRINT("Serial: IRP_MJ_DEVICE_CONTROL dispatch\n");
 	
-	/* FIXME: pend operation if possible */
-	
 	Stack = IoGetCurrentIrpStackLocation(Irp);
 	LengthIn = Stack->Parameters.DeviceIoControl.InputBufferLength;
 	LengthOut = Stack->Parameters.DeviceIoControl.OutputBufferLength;
-	Buffer = Irp->AssociatedIrp.SystemBuffer;
 	DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 	ComPortBase = (PUCHAR)DeviceExtension->BaseAddress;
+	IoControlCode = Stack->Parameters.DeviceIoControl.IoControlCode;
+	SerialGetUserBuffers(Irp, IoControlCode, &BufferIn, &BufferOut);
 	
 	/* FIXME: need to probe buffers */
 	/* FIXME: see http://www.osronline.com/ddkx/serial/serref_61bm.htm */
-	switch (Stack->Parameters.DeviceIoControl.IoControlCode)
+	switch (IoControlCode)
 	{
 		case IOCTL_SERIAL_CLEAR_STATS:
 		{
@@ -256,9 +320,13 @@
 			DPRINT("Serial: IOCTL_SERIAL_CLR_DTR\n");
 			/* FIXME: If the handshake flow control of the device is configured to 
 			 * automatically use DTR, return STATUS_INVALID_PARAMETER */
-			DeviceExtension->MCR &= ~SR_MCR_DTR;
-			WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
-			Status = STATUS_SUCCESS;
+			Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+			if (NT_SUCCESS(Status))
+			{
+				DeviceExtension->MCR &= ~SR_MCR_DTR;
+				WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
+				IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+			}
 			break;
 		}
 		case IOCTL_SERIAL_CLR_RTS:
@@ -266,9 +334,13 @@
 			DPRINT("Serial: IOCTL_SERIAL_CLR_RTS\n");
 			/* FIXME: If the handshake flow control of the device is configured to 
 			 * automatically use RTS, return STATUS_INVALID_PARAMETER */
-			DeviceExtension->MCR &= ~SR_MCR_RTS;
-			WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
-			Status = STATUS_SUCCESS;
+			Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+			if (NT_SUCCESS(Status))
+			{
+				DeviceExtension->MCR &= ~SR_MCR_RTS;
+				WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
+				IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+			}
 			break;
 		}
 		case IOCTL_SERIAL_CONFIG_SIZE:
@@ -276,11 +348,11 @@
 			/* Obsolete on Microsoft Windows 2000+ */
 			PULONG pConfigSize;
 			DPRINT("Serial: IOCTL_SERIAL_CONFIG_SIZE\n");
-			if (LengthOut != sizeof(ULONG) || Buffer == NULL)
+			if (LengthOut != sizeof(ULONG) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pConfigSize = (PULONG)Buffer;
+				pConfigSize = (PULONG)BufferOut;
 				*pConfigSize = 0;
 				Status = STATUS_SUCCESS;
 			}
@@ -291,14 +363,15 @@
 			DPRINT("Serial: IOCTL_SERIAL_GET_BAUD_RATE\n");
 			if (LengthOut < sizeof(SERIAL_BAUD_RATE))
 				Status = STATUS_BUFFER_TOO_SMALL;
-			else if (Buffer == NULL)
+			else if (BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				((PSERIAL_BAUD_RATE)Buffer)->BaudRate = DeviceExtension->BaudRate;
+				((PSERIAL_BAUD_RATE)BufferOut)->BaudRate = DeviceExtension->BaudRate;
 				Information = sizeof(SERIAL_BAUD_RATE);
 				Status = STATUS_SUCCESS;
 			}
+			break;
 		}
 		case IOCTL_SERIAL_GET_CHARS:
 		{
@@ -309,20 +382,33 @@
 		}
 		case IOCTL_SERIAL_GET_COMMSTATUS:
 		{
-			/* FIXME */
-			DPRINT1("Serial: IOCTL_SERIAL_GET_COMMSTATUS not implemented.\n");
-			Status = STATUS_NOT_IMPLEMENTED;
+			DPRINT("Serial: IOCTL_SERIAL_GET_COMMSTATUS\n");
+			if (LengthOut < sizeof(SERIAL_STATUS))
+			{
+				DPRINT("Serial: return STATUS_BUFFER_TOO_SMALL\n");
+				Status = STATUS_BUFFER_TOO_SMALL;
+			}
+			else if (BufferOut == NULL)
+			{
+				DPRINT("Serial: return STATUS_INVALID_PARAMETER\n");
+				Status = STATUS_INVALID_PARAMETER;
+			}
+			else
+			{
+				Status = SerialGetCommStatus((PSERIAL_STATUS)BufferOut, DeviceExtension);
+				Information = sizeof(SERIAL_STATUS);
+			}
 			break;
 		}
 		case IOCTL_SERIAL_GET_DTRRTS:
 		{
 			PULONG pDtrRts;
 			DPRINT("Serial: IOCTL_SERIAL_GET_DTRRTS\n");
-			if (LengthOut != sizeof(ULONG) || Buffer == NULL)
+			if (LengthOut != sizeof(ULONG) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pDtrRts = (PULONG)Buffer;
+				pDtrRts = (PULONG)BufferOut;
 				*pDtrRts = 0;
 				if (DeviceExtension->MCR & SR_MCR_DTR)
 					*pDtrRts |= SERIAL_DTR_STATE;
@@ -344,11 +430,11 @@
 			DPRINT("Serial: IOCTL_SERIAL_GET_LINE_CONTROL\n");
 			if (LengthOut < sizeof(SERIAL_LINE_CONTROL))
 				Status = STATUS_BUFFER_TOO_SMALL;
-			else if (Buffer == NULL)
+			else if (BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				*((PSERIAL_LINE_CONTROL)Buffer) = DeviceExtension->SerialLineControl;
+				*((PSERIAL_LINE_CONTROL)BufferOut) = DeviceExtension->SerialLineControl;
 				Information = sizeof(SERIAL_LINE_CONTROL);
 				Status = STATUS_SUCCESS;
 			}
@@ -358,11 +444,11 @@
 		{
 			PULONG pMCR;
 			DPRINT("Serial: IOCTL_SERIAL_GET_MODEM_CONTROL\n");
-			if (LengthOut != sizeof(ULONG) || Buffer == NULL)
+			if (LengthOut != sizeof(ULONG) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pMCR = (PULONG)Buffer;
+				pMCR = (PULONG)BufferOut;
 				*pMCR = DeviceExtension->MCR;
 				Status = STATUS_SUCCESS;
 			}
@@ -372,11 +458,11 @@
 		{
 			PULONG pMSR;
 			DPRINT("Serial: IOCTL_SERIAL_GET_MODEMSTATUS\n");
-			if (LengthOut != sizeof(ULONG) || Buffer == NULL)
+			if (LengthOut != sizeof(ULONG) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pMSR = (PULONG)Buffer;
+				pMSR = (PULONG)BufferOut;
 				*pMSR = DeviceExtension->MSR;
 				Status = STATUS_SUCCESS;
 			}
@@ -390,14 +476,14 @@
 				DPRINT("Serial: return STATUS_BUFFER_TOO_SMALL\n");
 				Status = STATUS_BUFFER_TOO_SMALL;
 			}
-			else if (Buffer == NULL)
+			else if (BufferOut == NULL)
 			{
 				DPRINT("Serial: return STATUS_INVALID_PARAMETER\n");
 				Status = STATUS_INVALID_PARAMETER;
 			}
 			else
 			{
-				Status = SerialGetCommProp((PSERIAL_COMMPROP)Buffer, DeviceExtension);
+				Status = SerialGetCommProp((PSERIAL_COMMPROP)BufferOut, DeviceExtension);
 				Information = sizeof(SERIAL_COMMPROP);
 			}
 			break;
@@ -410,7 +496,7 @@
 				DPRINT("Serial: return STATUS_BUFFER_TOO_SMALL\n");
 				Status = STATUS_BUFFER_TOO_SMALL;
 			}
-			else if (Buffer == NULL)
+			else if (BufferOut == NULL)
 			{
 				DPRINT("Serial: return STATUS_INVALID_PARAMETER\n");
 				Status = STATUS_INVALID_PARAMETER;
@@ -427,11 +513,11 @@
 		case IOCTL_SERIAL_GET_TIMEOUTS:
 		{
 			DPRINT("Serial: IOCTL_SERIAL_GET_TIMEOUTS\n");
-			if (LengthOut != sizeof(SERIAL_TIMEOUTS) || Buffer == NULL)
+			if (LengthOut != sizeof(SERIAL_TIMEOUTS) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				*(PSERIAL_TIMEOUTS)Buffer = DeviceExtension->SerialTimeOuts;
+				*(PSERIAL_TIMEOUTS)BufferOut = DeviceExtension->SerialTimeOuts;
 				Status = STATUS_SUCCESS;
 			}
 			break;
@@ -440,11 +526,11 @@
 		{
 			PULONG pWaitMask;
 			DPRINT("Serial: IOCTL_SERIAL_GET_WAIT_MASK\n");
-			if (LengthOut != sizeof(ULONG) || Buffer == NULL)
+			if (LengthOut != sizeof(ULONG) || BufferOut == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pWaitMask = (PULONG)Buffer;
+				pWaitMask = (PULONG)BufferOut;
 				*pWaitMask = DeviceExtension->WaitMask;
 				Status = STATUS_SUCCESS;
 			}
@@ -466,9 +552,27 @@
 		}
 		case IOCTL_SERIAL_PURGE:
 		{
-			/* FIXME */
-			DPRINT1("Serial: IOCTL_SERIAL_PURGE not implemented.\n");
-			Status = STATUS_NOT_IMPLEMENTED;
+			KIRQL Irql1, Irql2;
+			DPRINT("Serial: IOCTL_SERIAL_PURGE\n");
+			KeAcquireSpinLock(&DeviceExtension->InputBufferLock, &Irql1);
+			KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql2);
+			DeviceExtension->InputBuffer.ReadPosition = DeviceExtension->InputBuffer.WritePosition = 0;
+			DeviceExtension->OutputBuffer.ReadPosition = DeviceExtension->OutputBuffer.WritePosition = 0;
+			/* Clear receive/transmit buffers */
+			if (DeviceExtension->UartType >= Uart16550A)
+			{
+				/* 16550 UARTs also have FIFO queues, but they are unusable due to a bug */
+				Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				if (NT_SUCCESS(Status))
+				{
+					WRITE_PORT_UCHAR(SER_FCR(ComPortBase), SR_FCR_CLEAR_RCVR | SR_FCR_CLEAR_XMIT);
+					IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				}
+			}
+			else
+				Status = STATUS_SUCCESS;
+			KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql2);
+			KeReleaseSpinLock(&DeviceExtension->InputBufferLock, Irql1);
 			break;
 		}
 		case IOCTL_SERIAL_RESET_DEVICE:
@@ -482,11 +586,11 @@
 		{
 			PULONG pNewBaudRate;
 			DPRINT("Serial: IOCTL_SERIAL_SET_BAUD_RATE\n");
-			if (LengthIn != sizeof(ULONG) || Buffer == NULL)
+			if (LengthIn != sizeof(ULONG) || BufferIn == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pNewBaudRate = (PULONG)Buffer;
+				pNewBaudRate = (PULONG)BufferIn;
 				Status = SerialSetBaudRate(DeviceExtension, *pNewBaudRate);
 			}
 			break;
@@ -519,21 +623,31 @@
 			DPRINT("Serial: IOCTL_SERIAL_SET_DTR\n");
 			if (!(DeviceExtension->MCR & SR_MCR_DTR))
 			{
-				DeviceExtension->MCR |= SR_MCR_DTR;
-				WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
+				Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				if (NT_SUCCESS(Status))
+				{
+					DeviceExtension->MCR |= SR_MCR_DTR;
+					WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
+					IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				}
 			}
-			Status = STATUS_SUCCESS;
+			else
+				Status = STATUS_SUCCESS;
 			break;
 		}
 		case IOCTL_SERIAL_SET_FIFO_CONTROL:
 		{
 			DPRINT("Serial: IOCTL_SERIAL_SET_FIFO_CONTROL\n");
-			if (LengthIn != sizeof(ULONG) || Buffer == NULL)
+			if (LengthIn != sizeof(ULONG) || BufferIn == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				WRITE_PORT_UCHAR(SER_FCR(ComPortBase), (UCHAR)((*(PULONG)Buffer) & 0xff));
-				Status = STATUS_SUCCESS;
+				Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				if (NT_SUCCESS(Status))
+				{
+					WRITE_PORT_UCHAR(SER_FCR(ComPortBase), (UCHAR)((*(PULONG)BufferIn) & 0xff));
+					IoReleaseRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				}
 			}
 			break;
 		}
@@ -549,32 +663,55 @@
 			DPRINT("Serial: IOCTL_SERIAL_SET_LINE_CONTROL\n");
 			if (LengthIn < sizeof(SERIAL_LINE_CONTROL))
 				Status = STATUS_BUFFER_TOO_SMALL;
-			else if (Buffer == NULL)
+			else if (BufferIn == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
-				Status = SerialSetLineControl(DeviceExtension, (PSERIAL_LINE_CONTROL)Buffer);
+				Status = SerialSetLineControl(DeviceExtension, (PSERIAL_LINE_CONTROL)BufferIn);
 			break;
 		}
 		case IOCTL_SERIAL_SET_MODEM_CONTROL:
 		{
 			PULONG pMCR;
 			DPRINT("Serial: IOCTL_SERIAL_SET_MODEM_CONTROL\n");
-			if (LengthIn != sizeof(ULONG) || Buffer == NULL)
+			if (LengthIn != sizeof(ULONG) || BufferIn == NULL)
 				Status = STATUS_INVALID_PARAMETER;
 			else
 			{
-				pMCR = (PULONG)Buffer;
-				DeviceExtension->MCR = (UCHAR)(*pMCR & 0xff);
-				WRITE_PORT_UCHAR(SER_MCR(ComPortBase), DeviceExtension->MCR);
-				Status = STATUS_SUCCESS;
+				Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, (PVOID)DeviceExtension->ComPort);
+				if (NT_SUCCESS(Status))
+				{
+					pMCR = (PULONG)BufferIn;
[truncated at 1000 lines; 41370 more skipped]