Monday, September 27, 2010

Table Driven Madness

I've contemplated further work on NedOS, but the current barrier is pretty high. In order to enable interrupts (new style - ACPIA, not legacy PIC) I need to parse the AML tables. Retrieving the code isn't hard, but parsing it is a nightmare.

I have the source code of the Intel reference parser. It reminds me of some code from an earlier project - the table driven state machine.

Instead of a human readable handler (say for a FPS):
void onEvent(type)
{
switch(type)
{
case KEY_A: move_left();
case KEY_D: move_right();
case KEY_SPACE: fire();
}
}

you have this:
while( curState != END)
{
get_input(&input);
output = table[curState].out;
curState = table[curState][input].nextState;
}

On our project this made at least some sense. The hardware under development had the same tables, which allows you to fix bugs by patching the table ROM.

For pure software, I don't see the point. Now, instead of being able to read through some code and figure out what is going on, I get to state at tables like this:
/* Index Name Parser Args Interpreter Args ObjectType Class Type Flags */

/* 00 */ ACPI_OP ("Zero", ARGP_ZERO_OP, ARGI_ZERO_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT),
/* 01 */ ACPI_OP ("One", ARGP_ONE_OP, ARGI_ONE_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT),
/* 02 */ ACPI_OP ("Alias", ARGP_ALIAS_OP, ARGI_ALIAS_OP, ACPI_TYPE_LOCAL_ALIAS, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED),
/* 03 */ ACPI_OP ("Name", ARGP_NAME_OP, ARGI_NAME_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED),
/* 04 */ ACPI_OP ("ByteConst", ARGP_BYTE_OP, ARGI_BYTE_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT),
/* 05 */ ACPI_OP ("WordConst", ARGP_WORD_OP, ARGI_WORD_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT),
/* 06 */ ACPI_OP ("DwordConst", ARGP_DWORD_OP, ARGI_DWORD_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT),
/* 07 */ ACPI_OP ("String", ARGP_STRING_OP, ARGI_STRING_OP, ACPI_TYPE_STRING, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT),
/* 08 */ ACPI_OP ("Scope", ARGP_SCOPE_OP, ARGI_SCOPE_OP, ACPI_TYPE_LOCAL_SCOPE, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED),

Oh yea, that makes total sense. I see exactly what's happening here...

Tuesday, September 21, 2010

Stuff I've read lately

"G is for Gumshoe" (Sue Grafton)(audio) - I was surprised by this one. It was kind of hard to believe someone would care enough about Kinsey to put a hit on her. Harder to believe someone would take the offer for $1250 (actually $5000 for four people, including a judge and a DA). The story is somewhat confusing when the gunman ("G is for Gunman"?) shows up at the home of someone Kinsey is investigating. Who turns out to be a mass murderer, who is killed by the gunman. At least Kinsey managed not to kill anyone...

Sunday, September 12, 2010

Stuff I've read lately

"M is for Malice" (Sue Grafton)(audio) - I was surprised, this story actually had a character with a credible Christian testimony. I suddenly realized, "this guy is so dead". I was right. Again, it was impossible to determine who the murderer was. Not for lack of suspects:
  1. The older brother - work-aholic, possibly upset over money, bitter about past wrongs
  2. The younger brother - going through hero worship disappointment
  3. The youngest brother - always in need of more money
  4. The cook - feelings of disappointment to the family honor
  5. The nurse - who is so nondescript, even the other characters forget she's around most of the time
For a while, I figured it was #1. #2 gets arrested, and evidence points at #3. #4 really seemed to have some potential. So, of course, it was #5.

The worst part was there was a family which had been wronged in the past (mentioned briefly in the beginning, with no detail until near the end). But they were all supposed to be dead. Of course, one member had faked her own death, and set herself up as nurse so she could murder them. Of course.

Saturday, September 04, 2010

Stuff I've read lately

The Great Courses: Famous Romans (Rufus Fears)(audio) - This was not what I was expecting at all. It was more like a performance than a lecture. People were clapping at the end of each session...