Skip to content

Commit 2f951ac

Browse files
joevtdingusdev
authored andcommitted
ofnvram: Add f-segment? flag.
This is an Apple Network Server flag. It is unused on other versions of Open Firmware.
1 parent 9dc3cb9 commit 2f951ac

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

devices/common/ofnvram.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ uint16_t OfConfigAppl::checksum_partition() {
101101
return acc + (acc >> 16);
102102
}
103103

104-
static const string flag_names[8] = {
104+
static const string flag_names[] = {
105105
"little-endian?",
106106
"real-mode?",
107107
"auto-boot?",
108108
"diag-switch?",
109109
"fcode-debug?",
110110
"oem-banner?",
111111
"oem-logo?",
112-
"use-nvramrc?"
112+
"use-nvramrc?",
113+
"f-segment?" // ANS only
113114
};
115+
constexpr int num_flags = sizeof(flag_names) / sizeof(flag_names[0]);
114116

115117
static const map<string, std::tuple<int, uint16_t>> of_vars = {
116118
// name, type, offset
@@ -141,12 +143,12 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
141143
if (!this->validate())
142144
return _config_vars;
143145

144-
uint8_t of_flags = this->buf[12];
146+
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
145147

146148
// populate flags
147-
for (int i = 0; i < 8; i++) {
149+
for (unsigned i = 0; i < num_flags; i++) {
148150
_config_vars.push_back(std::make_pair(flag_names[i],
149-
((of_flags << i) & 0x80) ? "true" : "false"));
151+
(int32_t(of_flags << i) < 0) ? "true" : "false"));
150152
}
151153

152154
// populate the remaining variables
@@ -205,7 +207,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
205207
return false;
206208

207209
// check if the user tries to change a flag
208-
for (i = 0; i < 8; i++) {
210+
for (i = 0; i < num_flags; i++) {
209211
if (var_name == flag_names[i]) {
210212
if (value == "true")
211213
flag = 1;
@@ -215,15 +217,15 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
215217
cout << "Invalid property value: " << value << endl;
216218
return false;
217219
}
218-
uint8_t flag_bit = 0x80U >> i;
219-
uint8_t of_flags = this->buf[12];
220+
uint32_t flag_bit = 0x80000000U >> i;
221+
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
220222

221223
if (flag)
222224
of_flags |= flag_bit;
223225
else
224226
of_flags &= ~flag_bit;
225227

226-
this->buf[12] = of_flags;
228+
WRITE_DWORD_BE_A(&this->buf[12], of_flags);
227229
this->update_partition();
228230
return true;
229231
}

0 commit comments

Comments
 (0)