[SeaBIOS] [PATCH] Reduce size of certain global variables to reduce bios size
Bruce Rogers
brogers at suse.com
Tue Mar 24 17:22:49 CET 2015
In doing a pass through all the code, I found a number of global
variables which were reasonable candidates to reduce in size,
typically from int to u8. Also a large array in the keyboard code
was packed.
This change reduces the resulting size by 240 bytes in my case.
Signed-off-by: Bruce Rogers <brogers at suse.com>
---
src/boot.c | 16 ++++++++--------
src/bootsplash.c | 2 +-
src/hw/usb-xhci.c | 31 +++++++++++++++----------------
src/hw/usb.c | 2 +-
src/kbd.c | 2 +-
src/stacks.c | 2 +-
src/vgahooks.c | 6 +++---
7 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/src/boot.c b/src/boot.c
index d6b1fb7..8238f62 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -26,7 +26,7 @@
****************************************************************/
static char **Bootorder VARVERIFY32INIT;
-static int BootorderCount;
+static u8 BootorderCount;
static void
loadBootOrder(void)
@@ -240,7 +240,7 @@ int bootprio_find_usb(struct usbdevice_s *usbdev, int lun)
****************************************************************/
static int BootRetryTime;
-static int CheckFloppySig = 1;
+static u8 CheckFloppySig = 1;
#define DEFAULT_PRIO 9999
@@ -520,8 +520,8 @@ struct bev_s {
u32 vector;
};
static struct bev_s BEV[20];
-static int BEVCount;
-static int HaveHDBoot, HaveFDBoot;
+static u8 BEVCount;
+static u8 HaveHDBoot, HaveFDBoot;
static void
add_bev(int type, u32 vector)
@@ -600,7 +600,7 @@ call_boot_entry(struct segoff_s bootsegip, u8 bootdrv)
// Boot from a disk (either floppy or harddrive)
static void
-boot_disk(u8 bootdrv, int checksig)
+boot_disk(u8 bootdrv, u8 checksig)
{
u16 bootseg = 0x07c0;
@@ -700,7 +700,7 @@ boot_fail(void)
// Determine next boot method and attempt a boot using it.
static void
-do_boot(int seq_nr)
+do_boot(u8 seq_nr)
{
if (! CONFIG_BOOT)
panic("Boot support not compiled in.\n");
@@ -740,14 +740,14 @@ do_boot(int seq_nr)
call16_int(0x18, &br);
}
-int BootSequence VARLOW = -1;
+u8 BootSequence VARLOW = -1;
// Boot Failure recovery: try the next device.
void VISIBLE32FLAT
handle_18(void)
{
debug_enter(NULL, DEBUG_HDL_18);
- int seq = BootSequence + 1;
+ u8 seq = BootSequence + 1;
BootSequence = seq;
do_boot(seq);
}
diff --git a/src/bootsplash.c b/src/bootsplash.c
index c572685..0b66a04 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -91,7 +91,7 @@ find_videomode(struct vbe_info *vesa_info, struct vbe_mode_info *mode_info
}
}
-static int BootsplashActive;
+static u8 BootsplashActive;
void
enable_bootsplash(void)
diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c
index fd58334..a92a8b3 100644
--- a/src/hw/usb-xhci.c
+++ b/src/hw/usb-xhci.c
@@ -271,16 +271,14 @@ static const char *speed_name[16] = {
[ 4 ] = "Super",
};
-static const int speed_from_xhci[16] = {
- [ 0 ] = -1,
- [ 1 ] = USB_FULLSPEED,
- [ 2 ] = USB_LOWSPEED,
- [ 3 ] = USB_HIGHSPEED,
- [ 4 ] = USB_SUPERSPEED,
- [ 5 ... 15 ] = -1,
+static const u8 speed_from_xhci[] = {
+ [ 0 ] = USB_FULLSPEED,
+ [ 1 ] = USB_LOWSPEED,
+ [ 2 ] = USB_HIGHSPEED,
+ [ 3 ] = USB_SUPERSPEED,
};
-static const int speed_to_xhci[] = {
+static const u8 speed_to_xhci[] = {
[ USB_FULLSPEED ] = 1,
[ USB_LOWSPEED ] = 2,
[ USB_HIGHSPEED ] = 3,
@@ -350,23 +348,24 @@ xhci_hub_reset(struct usbhub_s *hub, u32 port)
{
struct usb_xhci_s *xhci = container_of(hub->cntl, struct usb_xhci_s, usb);
u32 portsc = readl(&xhci->pr[port].portsc);
- int rc;
+ unsigned int index;
+ int rc = -1;
switch (xhci_get_field(portsc, XHCI_PORTSC_PLS)) {
- case PLS_U0:
- rc = speed_from_xhci[xhci_get_field(portsc, XHCI_PORTSC_SPEED)];
- break;
case PLS_POLLING:
xhci_print_port_state(3, __func__, port, portsc);
portsc |= XHCI_PORTSC_PR;
writel(&xhci->pr[port].portsc, portsc);
if (wait_bit(&xhci->pr[port].portsc, XHCI_PORTSC_PED, XHCI_PORTSC_PED, 100) != 0)
- return -1;
+ return rc;
portsc = readl(&xhci->pr[port].portsc);
- rc = speed_from_xhci[xhci_get_field(portsc, XHCI_PORTSC_SPEED)];
+ // fall through
+ case PLS_U0:
+ index = xhci_get_field(portsc, XHCI_PORTSC_SPEED) - 1;
+ if (index < 4)
+ rc = speed_from_xhci[index];
break;
default:
- rc = -1;
break;
}
@@ -834,7 +833,7 @@ xhci_alloc_inctx(struct usbdevice_s *usbdev, int maxepid)
struct xhci_slotctx *slot = (void*)&in[1 << xhci->context64];
slot->ctx[0] |= maxepid << 27; // context entries
- slot->ctx[0] |= speed_to_xhci[usbdev->speed] << 20;
+ slot->ctx[0] |= (u32)speed_to_xhci[usbdev->speed] << 20;
// Set high-speed hub flags.
struct usbdevice_s *hubdev = usbdev->hub->usbdev;
diff --git a/src/hw/usb.c b/src/hw/usb.c
index 1b4ea8b..6ceeda5 100644
--- a/src/hw/usb.c
+++ b/src/hw/usb.c
@@ -278,7 +278,7 @@ set_configuration(struct usb_pipe *pipe, u16 val)
* Initialization and enumeration
****************************************************************/
-static const int speed_to_ctlsize[] = {
+static const u16 speed_to_ctlsize[] = {
[ USB_FULLSPEED ] = 8,
[ USB_LOWSPEED ] = 8,
[ USB_HIGHSPEED ] = 64,
diff --git a/src/kbd.c b/src/kbd.c
index a5a1ad9..43ae351 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -289,7 +289,7 @@ static struct scaninfo {
u16 control;
u16 alt;
u8 lock_flags;
-} scan_to_scanascii[] VAR16 = {
+} PACKED scan_to_scanascii[] VAR16 = {
{ none, none, none, none, none },
{ 0x011b, 0x011b, 0x011b, 0x0100, none }, /* escape */
{ 0x0231, 0x0221, none, 0x7800, none }, /* 1! */
diff --git a/src/stacks.c b/src/stacks.c
index 1dbdfe9..e510a2f 100644
--- a/src/stacks.c
+++ b/src/stacks.c
@@ -742,7 +742,7 @@ mutex_unlock(struct mutex_s *mutex)
* Thread preemption
****************************************************************/
-int CanPreempt VARFSEG;
+u8 CanPreempt VARFSEG;
static u32 PreemptCount;
// Turn on RTC irqs and arrange for them to check the 32bit threads.
diff --git a/src/vgahooks.c b/src/vgahooks.c
index 6a4acfe..3fc716a 100644
--- a/src/vgahooks.c
+++ b/src/vgahooks.c
@@ -18,7 +18,7 @@
#define VH_INTEL 2
#define VH_SMI 3
-int VGAHookHandlerType VARFSEG;
+u8 VGAHookHandlerType VARFSEG;
static void
handle_155fXX(struct bregs *regs)
@@ -308,7 +308,7 @@ handle_155f(struct bregs *regs)
return;
}
- int htype = GET_GLOBAL(VGAHookHandlerType);
+ u8 htype = GET_GLOBAL(VGAHookHandlerType);
switch (htype) {
case VH_VIA: via_155f(regs); break;
case VH_INTEL: intel_155f(regs); break;
@@ -325,7 +325,7 @@ handle_157f(struct bregs *regs)
return;
}
- int htype = GET_GLOBAL(VGAHookHandlerType);
+ u8 htype = GET_GLOBAL(VGAHookHandlerType);
switch (htype) {
case VH_SMI: smi_157f(regs); break;
default: handle_157fXX(regs); break;
--
1.9.0
More information about the SeaBIOS
mailing list