Add overflow flag checking

This is to ensure that we check for and flag buffer overflow flag from
the BIOS.

The logic should be:

```
1. BIOS_switch ^ BMC_switch == 0 → No overflow incident
  a. CONTINUE
2. BIOS_switch ^ BMC_switch == 1 → an unlogged overflow incident has occurred
  b. Log the overflow incident
  c. Toggle the BMC overflow flag
```

Tested: Added unit test

Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I25c50a8de93900480413389d7d2a89b9be4b5643
diff --git a/src/buffer.cpp b/src/buffer.cpp
index 0254cac..3af1125 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -269,6 +269,36 @@
                     currentUeRegionSize, ueLogData.size()));
 }
 
+bool BufferImpl::checkForOverflowAndAcknowledge()
+{
+    // Ensure cachedBufferHeader is up-to-date
+    readBufferHeader();
+
+    uint32_t biosSideFlags =
+        boost::endian::little_to_native(cachedBufferHeader.biosFlags);
+    uint32_t bmcSideFlags =
+        boost::endian::little_to_native(cachedBufferHeader.bmcFlags);
+
+    // Design: (BIOS_switch ^ BMC_switch) & BIT1 == BIT1 -> unlogged overflow
+    // This means if the overflow bit differs, there's an
+    // unacknowledged overflow.
+    if ((biosSideFlags ^ bmcSideFlags) &
+        static_cast<uint32_t>(BufferFlags::overflow))
+    {
+        // Overflow incident has occurred and BMC has not acknowledged it.
+        // Toggle BMC's view of the overflow flag to acknowledge.
+        uint32_t newBmcFlags =
+            bmcSideFlags ^ static_cast<uint32_t>(BufferFlags::overflow);
+        updateBmcFlags(newBmcFlags);
+
+        // Overflow was detected and acknowledged
+        return true;
+    }
+
+    // No new overflow incident or already acknowledged
+    return false;
+}
+
 EntryPair BufferImpl::readEntry()
 {
     struct QueueEntryHeader entryHeader = readEntryHeader();