shithub: riscv

Download patch

ref: f0ff0fb0544841d73bc29872d8e2fb4a6a8a5e06
parent: 040166493db3bd6f528cc08e2d0cc2c638c560a5
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Oct 18 15:15:53 EDT 2014

efi: simplify bootscreen code

--- a/sys/src/boot/efi/efi.c
+++ b/sys/src/boot/efi/efi.c
@@ -199,13 +199,16 @@
 	}
 }
 
+
 static int
 topbit(ulong mask)
 {
-	int bit;
+	int bit = 0;
 
-	for(bit=1; bit < 32 && (mask >> bit) != 0; bit++)
-		;
+	while(mask != 0){
+		mask >>= 1;
+		bit++;
+	}
 	return bit;
 }
 
@@ -212,22 +215,33 @@
 static int
 lowbit(ulong mask)
 {
-	int bit;
+	int bit = 0;
 
-	for(bit=0; bit < 32 && (mask & (1<<bit)) == 0; bit++)
-		;
+	while((mask & 1) == 0){
+		mask >>= 1;
+		bit++;
+	}
 	return bit;
 }
 
-static char*
-modeinfostr(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, char *s)
+static void
+screenconf(char **cfg)
 {
+	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
 	ulong mr, mg, mb, mx, mc;
-	int n, depth;
+	int bits, depth;
+	char *s;
 
+	gop = nil;
+	if(LocateProtocol(&EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, nil, &gop) || gop == nil)
+		return;
+
+	if((info = gop->Mode->Info) == nil)
+		return;
+
 	switch(info->PixelFormat){
 	default:
-		return nil;	/* unsupported */
+		return;	/* unsupported */
 
 	case PixelRedGreenBlueReserved8BitPerColor:
 		mr = 0x000000ff;
@@ -235,6 +249,7 @@
 		mb = 0x00ff0000;
 		mx = 0xff000000;
 		break;
+
 	case PixelBlueGreenRedReserved8BitPerColor:
 		mb = 0x000000ff;
 		mg = 0x0000ff00;
@@ -241,6 +256,7 @@
 		mr = 0x00ff0000;
 		mx = 0xff000000;
 		break;
+
 	case PixelBitMask:
 		mr = info->PixelInformation.RedMask;
 		mg = info->PixelInformation.GreenMask;
@@ -249,8 +265,11 @@
 		break;
 	}
 
-	depth = topbit(mr | mg | mb | mx);
+	if((depth = topbit(mr | mg | mb | mx)) == 0)
+		return;
 
+	s = *cfg;
+	memmove(s, "*bootscreen=", 12), s += 12;
 	s = decfmt(s, 0, info->PixelsPerScanLine), *s++ = 'x';
 	s = decfmt(s, 0, info->VerticalResolution), *s++ = 'x';
 	s = decfmt(s, 0, depth), *s++ = ' ';
@@ -271,31 +290,12 @@
 		} else {
 			break;
 		}
-		n = depth - lowbit(mc);
-		s = decfmt(s, 0, n);
-		depth -= n;
+		bits = depth - lowbit(mc);
+		s = decfmt(s, 0, bits);
+		depth -= bits;
 	}
-	*s = '\0';
-
-	return s;
-}
-
-static void
-screenconf(char **cfg)
-{
-	char *s;
-
-	gop = nil;
-	if(LocateProtocol(&EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, nil, &gop) || gop == nil)
-		return;
-
-	s = *cfg;
-	memmove(s, "*bootscreen=", 12), s += 12;
-	if((s = modeinfostr(gop->Mode->Info, s)) == nil){
-		**cfg = '\0';
-		return;
-	}
 	*s++ = ' ';
+
 	*s++ = '0', *s++ = 'x';
 	s = hexfmt(s, 0, gop->Mode->FrameBufferBase), *s++ = '\n';
 	*s = '\0';