Skip to content

Commit

Permalink
nvbios: parse D unk2 table
Browse files Browse the repository at this point in the history
  • Loading branch information
karolherbst committed Nov 20, 2016
1 parent 7f21141 commit 0728a16
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions nvbios/D.c
Expand Up @@ -24,6 +24,8 @@

#include "bios.h"

static void envy_bios_parse_D_unk2(struct envy_bios *);

struct D_known_tables {
uint8_t offset;
uint16_t *ptr;
Expand Down Expand Up @@ -66,6 +68,7 @@ envy_bios_parse_bit_D(struct envy_bios *bios, struct envy_bios_bit_entry *bit)
idx++;

/* parse tables */
envy_bios_parse_D_unk2(bios);

return 0;
}
Expand Down Expand Up @@ -94,3 +97,58 @@ envy_bios_print_bit_D(struct envy_bios *bios, FILE *out, unsigned mask)

fprintf(out, "\n");
}

static void
envy_bios_parse_D_unk2(struct envy_bios *bios)
{
struct envy_bios_D_unk2 *unk2 = &bios->D.unk2;
int err = 0, i;

if (!unk2->offset)
return;

bios_u8(bios, unk2->offset, &unk2->version);
switch (unk2->version) {
case 0x20:
err |= bios_u8(bios, unk2->offset + 0x1, &unk2->hlen);
err |= bios_u8(bios, unk2->offset + 0x2, &unk2->rlen);
err |= bios_u8(bios, unk2->offset + 0x3, &unk2->entriesnum);
unk2->valid = !err;
break;
default:
ENVY_BIOS_ERR("Unknown UNK2 table version 0x%x\n", unk2->version);
return;
}

unk2->entries = malloc(unk2->entriesnum * sizeof(struct envy_bios_D_unk2_entry));
for (i = 0; i < unk2->entriesnum; ++i) {
struct envy_bios_D_unk2_entry *e = &unk2->entries[i];
e->offset = unk2->offset + unk2->hlen + i * unk2->rlen;
}
}

void
envy_bios_print_D_unk2(struct envy_bios *bios, FILE *out, unsigned mask)
{
struct envy_bios_D_unk2 *unk2 = &bios->D.unk2;
int i;

if (!unk2->offset || !(mask & ENVY_BIOS_PRINT_D))
return;
if (!unk2->valid) {
ENVY_BIOS_ERR("Failed to parse D UNK2 table at 0x%x, version %x\n\n", unk2->offset, unk2->version);
return;
}

fprintf(out, "D UNK2 table at 0x%x, version %x\n", unk2->offset, unk2->version);
envy_bios_dump_hex(bios, out, unk2->offset, unk2->hlen, mask);
if (mask & ENVY_BIOS_PRINT_VERBOSE) fprintf(out, "\n");

for (i = 0; i < unk2->entriesnum; ++i) {
struct envy_bios_D_unk2_entry *e = &unk2->entries[i];
envy_bios_dump_hex(bios, out, e->offset, unk2->rlen, mask);
if (mask & ENVY_BIOS_PRINT_VERBOSE) fprintf(out, "\n");
}

fprintf(out, "\n");
}
1 change: 1 addition & 0 deletions nvbios/bios.h
Expand Up @@ -1621,6 +1621,7 @@ void envy_bios_print_mem_unk0d(struct envy_bios *bios, FILE *out, unsigned mask)

int envy_bios_parse_bit_D (struct envy_bios *, struct envy_bios_bit_entry *);
void envy_bios_print_bit_D (struct envy_bios *, FILE *out, unsigned mask);
void envy_bios_print_D_unk2(struct envy_bios *, FILE *out, unsigned mask);

int envy_bios_parse_dcb (struct envy_bios *bios);
void envy_bios_print_dcb (struct envy_bios *bios, FILE *out, unsigned mask);
Expand Down
2 changes: 2 additions & 0 deletions nvbios/print.c
Expand Up @@ -453,6 +453,8 @@ void envy_bios_print (struct envy_bios *bios, FILE *out, unsigned mask) {
envy_bios_print_power_unk90(bios, stdout, mask);
envy_bios_print_power_unk94(bios, stdout, mask);
envy_bios_print_power_unk98(bios, stdout, mask);

envy_bios_print_D_unk2(bios, stdout, mask);
break;
}
if (mask & ENVY_BIOS_PRINT_BLOCKS) {
Expand Down

0 comments on commit 0728a16

Please sign in to comment.