From 15235fb0b42c91513c30117155dc1b5a020baf76 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 13 Jul 2012 13:24:05 +0800 Subject: [PATCH] Kernel - Split drvutil.c into disk and video variants --- KernelLand/Kernel/Makefile | 3 +- KernelLand/Kernel/drvutil_disk.c | 169 ++++++++++++++++++ .../Kernel/{drvutil.c => drvutil_video.c} | 161 +---------------- 3 files changed, 172 insertions(+), 161 deletions(-) create mode 100644 KernelLand/Kernel/drvutil_disk.c rename KernelLand/Kernel/{drvutil.c => drvutil_video.c} (79%) diff --git a/KernelLand/Kernel/Makefile b/KernelLand/Kernel/Makefile index 153fcafa..42b47dcf 100644 --- a/KernelLand/Kernel/Makefile +++ b/KernelLand/Kernel/Makefile @@ -51,7 +51,8 @@ BUILDINFO_OBJ := $(OBJDIR)buildinfo.o$(OBJSUFFIX) BUILDINFO_SRC := $(OBJDIR)buildinfo.c$(OBJSUFFIX) OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) -OBJ += heap.o drvutil.o logging.o debug.o lib.o libc.o adt.o time.o +OBJ += heap.o logging.o debug.o lib.o libc.o adt.o time.o +OBJ += drvutil_video.o drvutil_disk.o OBJ += messages.o modules.o syscalls.o system.o OBJ += threads.o mutex.o semaphore.o workqueue.o events.o OBJ += drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o diff --git a/KernelLand/Kernel/drvutil_disk.c b/KernelLand/Kernel/drvutil_disk.c new file mode 100644 index 00000000..db4d631a --- /dev/null +++ b/KernelLand/Kernel/drvutil_disk.c @@ -0,0 +1,169 @@ +/* + * Acess2 Kernel + * - By John Hodge + * + * drvutil_disk.c + * - Storage Driver Helper Functions + */ +#define DEBUG 0 +#include +#include + +// --- Disk Driver Helpers --- +Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, void *Argument) +{ + Uint8 tmp[BlockSize]; // C99 + Uint64 block = Start / BlockSize; + int offset = Start - block * BlockSize; + int leading = BlockSize - offset; + Uint64 num; + int tailings; + Uint64 ret; + + ENTER("XStart XLength pBuffer pReadBlocks XBlockSize pArgument", + Start, Length, Buffer, ReadBlocks, BlockSize, Argument); + + // Non aligned start, let's fix that! + if(offset != 0) + { + if(leading > Length) leading = Length; + LOG("Reading %i bytes from Block1+%i", leading, offset); + ret = ReadBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('i', 0); + return 0; + } + memcpy( Buffer, &tmp[offset], leading ); + + if(leading == Length) { + LEAVE('i', leading); + return leading; + } + + Buffer = (Uint8*)Buffer + leading; + block ++; + num = ( Length - leading ) / BlockSize; + tailings = Length - num * BlockSize - leading; + } + else { + num = Length / BlockSize; + tailings = Length % BlockSize; + } + + // Read central blocks + if(num) + { + LOG("Reading %i blocks", num); + ret = ReadBlocks(block, num, Buffer, Argument); + if(ret != num ) { + LEAVE('X', leading + ret * BlockSize); + return leading + ret * BlockSize; + } + } + + // Read last tailing block + if(tailings != 0) + { + LOG("Reading %i bytes from last block", tailings); + block += num; + Buffer = (Uint8*)Buffer + num * BlockSize; + ret = ReadBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('X', leading + num * BlockSize); + return leading + num * BlockSize; + } + memcpy( Buffer, tmp, tailings ); + } + + LEAVE('X', Length); + return Length; +} + +Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, + Uint64 BlockSize, void *Argument) +{ + Uint8 tmp[BlockSize]; // C99 + Uint64 block = Start / BlockSize; + int offset = Start - block * BlockSize; + int leading = BlockSize - offset; + Uint64 num; + int tailings; + Uint64 ret; + + ENTER("XStart XLength pBuffer pReadBlocks pWriteBlocks XBlockSize pArgument", + Start, Length, Buffer, ReadBlocks, WriteBlocks, BlockSize, Argument); + + // Non aligned start, let's fix that! + if(offset != 0) + { + if(leading > Length) leading = Length; + LOG("Writing %i bytes to Block1+%i", leading, offset); + // Read a copy of the block + ret = ReadBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('i', 0); + return 0; + } + // Modify + memcpy( &tmp[offset], Buffer, leading ); + // Write Back + ret = WriteBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('i', 0); + return 0; + } + + if(leading == Length) { + LEAVE('i', leading); + return leading; + } + + Buffer = (Uint8*)Buffer + leading; + block ++; + num = ( Length - leading ) / BlockSize; + tailings = Length - num * BlockSize - leading; + } + else { + num = Length / BlockSize; + tailings = Length % BlockSize; + } + + // Read central blocks + if(num) + { + LOG("Writing %i blocks", num); + ret = WriteBlocks(block, num, Buffer, Argument); + if(ret != num ) { + LEAVE('X', leading + ret * BlockSize); + return leading + ret * BlockSize; + } + } + + // Read last tailing block + if(tailings != 0) + { + LOG("Writing %i bytes to last block", tailings); + block += num; + Buffer = (Uint8*)Buffer + num * BlockSize; + // Read + ret = ReadBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('X', leading + num * BlockSize); + return leading + num * BlockSize; + } + // Modify + memcpy( tmp, Buffer, tailings ); + // Write + ret = WriteBlocks(block, 1, tmp, Argument); + if(ret != 1) { + LEAVE('X', leading + num * BlockSize); + return leading + num * BlockSize; + } + + } + + LEAVE('X', Length); + return Length; +} diff --git a/KernelLand/Kernel/drvutil.c b/KernelLand/Kernel/drvutil_video.c similarity index 79% rename from KernelLand/Kernel/drvutil.c rename to KernelLand/Kernel/drvutil_video.c index d2c86bfb..6e633869 100644 --- a/KernelLand/Kernel/drvutil.c +++ b/KernelLand/Kernel/drvutil_video.c @@ -3,11 +3,10 @@ * - By John Hodge * * drvutil.c - * - Common Driver/Filesystem Helper Functions + * - Video Driver Helper Functions */ #define DEBUG 0 #include -#include #include // === TYPES === @@ -580,161 +579,3 @@ void DrvUtil_Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uin } -// --- Disk Driver Helpers --- -Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, void *Argument) -{ - Uint8 tmp[BlockSize]; // C99 - Uint64 block = Start / BlockSize; - int offset = Start - block * BlockSize; - int leading = BlockSize - offset; - Uint64 num; - int tailings; - Uint64 ret; - - ENTER("XStart XLength pBuffer pReadBlocks XBlockSize pArgument", - Start, Length, Buffer, ReadBlocks, BlockSize, Argument); - - // Non aligned start, let's fix that! - if(offset != 0) - { - if(leading > Length) leading = Length; - LOG("Reading %i bytes from Block1+%i", leading, offset); - ret = ReadBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('i', 0); - return 0; - } - memcpy( Buffer, &tmp[offset], leading ); - - if(leading == Length) { - LEAVE('i', leading); - return leading; - } - - Buffer = (Uint8*)Buffer + leading; - block ++; - num = ( Length - leading ) / BlockSize; - tailings = Length - num * BlockSize - leading; - } - else { - num = Length / BlockSize; - tailings = Length % BlockSize; - } - - // Read central blocks - if(num) - { - LOG("Reading %i blocks", num); - ret = ReadBlocks(block, num, Buffer, Argument); - if(ret != num ) { - LEAVE('X', leading + ret * BlockSize); - return leading + ret * BlockSize; - } - } - - // Read last tailing block - if(tailings != 0) - { - LOG("Reading %i bytes from last block", tailings); - block += num; - Buffer = (Uint8*)Buffer + num * BlockSize; - ret = ReadBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('X', leading + num * BlockSize); - return leading + num * BlockSize; - } - memcpy( Buffer, tmp, tailings ); - } - - LEAVE('X', Length); - return Length; -} - -Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, - tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, - Uint64 BlockSize, void *Argument) -{ - Uint8 tmp[BlockSize]; // C99 - Uint64 block = Start / BlockSize; - int offset = Start - block * BlockSize; - int leading = BlockSize - offset; - Uint64 num; - int tailings; - Uint64 ret; - - ENTER("XStart XLength pBuffer pReadBlocks pWriteBlocks XBlockSize pArgument", - Start, Length, Buffer, ReadBlocks, WriteBlocks, BlockSize, Argument); - - // Non aligned start, let's fix that! - if(offset != 0) - { - if(leading > Length) leading = Length; - LOG("Writing %i bytes to Block1+%i", leading, offset); - // Read a copy of the block - ret = ReadBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('i', 0); - return 0; - } - // Modify - memcpy( &tmp[offset], Buffer, leading ); - // Write Back - ret = WriteBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('i', 0); - return 0; - } - - if(leading == Length) { - LEAVE('i', leading); - return leading; - } - - Buffer = (Uint8*)Buffer + leading; - block ++; - num = ( Length - leading ) / BlockSize; - tailings = Length - num * BlockSize - leading; - } - else { - num = Length / BlockSize; - tailings = Length % BlockSize; - } - - // Read central blocks - if(num) - { - LOG("Writing %i blocks", num); - ret = WriteBlocks(block, num, Buffer, Argument); - if(ret != num ) { - LEAVE('X', leading + ret * BlockSize); - return leading + ret * BlockSize; - } - } - - // Read last tailing block - if(tailings != 0) - { - LOG("Writing %i bytes to last block", tailings); - block += num; - Buffer = (Uint8*)Buffer + num * BlockSize; - // Read - ret = ReadBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('X', leading + num * BlockSize); - return leading + num * BlockSize; - } - // Modify - memcpy( tmp, Buffer, tailings ); - // Write - ret = WriteBlocks(block, 1, tmp, Argument); - if(ret != 1) { - LEAVE('X', leading + num * BlockSize); - return leading + num * BlockSize; - } - - } - - LEAVE('X', Length); - return Length; -} -- 2.20.1