Results: Implement namespaced, type-safe results.

Because I was working on multiple things at once, this commit also:
- Adds wrappers for/linker flags to wrap CXX exceptions to make them
  abort. This saves ~0x8000 of memory in every system module.
- Broadly replaces lines of the pattern if (cond) { return ResultX; }
  with R_UNLESS(!cond, ResultX());.
- Reworks the R_TRY_CATCH macros (and the result macros in general).
This commit is contained in:
Michael Scire 2019-10-24 01:40:44 -07:00 committed by SciresM
parent 15773e4755
commit 4059dc6187
169 changed files with 2172 additions and 1868 deletions

View file

@ -29,8 +29,6 @@ namespace sts::boot {
constexpr u32 DefaultBatteryVendor = static_cast<u32>('A');
constexpr u32 DefaultBatteryVersion = 0;
constexpr Result ResultCalInvalidCrc = 0xCAC6; /* TODO: Verify this really is cal, move to libstrat results. */
/* Helpers. */
constexpr u16 GetCrc16(const void *data, size_t size) {
constexpr u16 s_crc_table[0x10] = {
@ -51,10 +49,9 @@ namespace sts::boot {
Result ValidateCalibrationCrc16(const void *data, size_t size) {
const u8 *data_u8 = reinterpret_cast<const u8 *>(data);
if (GetCrc16(data, size - sizeof(u16)) != *(reinterpret_cast<const u16 *>(&data_u8[size - sizeof(u16)]))) {
return ResultCalInvalidCrc;
}
return ResultSuccess;
const bool crc_valid = GetCrc16(data, size - sizeof(u16)) == *(reinterpret_cast<const u16 *>(&data_u8[size - sizeof(u16)]));
R_UNLESS(crc_valid, cal::ResultCalibrationDataCrcError());
return ResultSuccess();
}
Result GetBatteryVendorImpl(u32 *vendor) {
@ -68,7 +65,7 @@ namespace sts::boot {
R_TRY(ValidateCalibrationCrc16(battery_lot, sizeof(battery_lot)));
*vendor = battery_lot[7];
return ResultSuccess;
return ResultSuccess();
}
Result GetBatteryVersionImpl(u32 *version) {
@ -82,7 +79,7 @@ namespace sts::boot {
R_TRY(ValidateCalibrationCrc16(battery_version, sizeof(battery_version)));
*version = battery_version[0];
return ResultSuccess;
return ResultSuccess();
}
}