HardwareSerial improvements and fixes

This patch series applies a number of cleanups and fixes to the HardwareSerial code. The individual commit messages should be self-explanatory (and I've tried to reference existing tickets where possible), but I'll summarize what's in this series:
 - Atomicity fixes. With this series, it is possible to use and flush the Serial port from interrupt handlers, without the Arduino locking up every other attempt.
 - Code size optimizations (which are compensated by the new atomicity code, so the net result is the size stays the same before and after the entire series)
 - Miscellaneous cleanups (mostly reducing of code duplication)

The last patch in this series, which adds an API to toggle blocking behaviour of HardwareSerial::write is not ready to merge yet, since I'm not entirely sure what the best form for this API is (methods vs an attribute, defines vs an enum, etc.) and I couldn't find any similar examples just now.