summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2017-03-15 13:50:51 +0000
committerroot <root@lamia.panaceas.james.local>2017-03-15 13:50:51 +0000
commit2dd7ea9b7a34fd02c10b67bccebfb3c04b7ab3bf (patch)
treef145c6f6ad2dd52e271f1b84a4cfb8b8f0c6ce07
parentf327ade1d0333deee519b2c2977f8edae5b9fa3d (diff)
downloadtboot-2dd7ea9b7a34fd02c10b67bccebfb3c04b7ab3bf.tar.gz
tboot-2dd7ea9b7a34fd02c10b67bccebfb3c04b7ab3bf.tar.bz2
tboot-2dd7ea9b7a34fd02c10b67bccebfb3c04b7ab3bf.zip
patch up C99isms and a missing defineHEADmaster
-rw-r--r--tboot/acmod.c7
-rw-r--r--tboot/acpi.c18
-rw-r--r--tboot/cmdline.c3
-rw-r--r--tboot/com.c4
-rw-r--r--tboot/heap.c12
-rw-r--r--tboot/include/tb_policy.h15
-rw-r--r--tboot/include/tpm.h9
-rw-r--r--tboot/launch.S10
-rw-r--r--tboot/misc.c3
-rw-r--r--tboot/mtrrs.c22
-rw-r--r--tboot/policy.c30
-rw-r--r--tboot/tpm_12.c3
-rw-r--r--tboot/tpm_20.c8
-rw-r--r--tboot/txt.c3
-rw-r--r--tboot/vga.c7
-rw-r--r--tboot/vmac.c5
-rw-r--r--tboot/vsprintf.c3
17 files changed, 101 insertions, 61 deletions
diff --git a/tboot/acmod.c b/tboot/acmod.c
index 6601222..ac063b1 100644
--- a/tboot/acmod.c
+++ b/tboot/acmod.c
@@ -296,6 +296,7 @@ void print_txt_caps(const char *prefix, txt_caps_t caps)
static void print_acm_hdr(const acm_hdr_t *hdr, const char *mod_name)
{
+ unsigned int i;
acm_info_table_t *info_table;
printk(TBOOT_DETA"AC module header dump for %s:\n",
@@ -369,7 +370,7 @@ static void print_acm_hdr(const acm_hdr_t *hdr, const char *mod_name)
return;
}
printk(TBOOT_DETA"\t\t count: %u\n", chipset_id_list->count);
- for ( unsigned int i = 0; i < chipset_id_list->count; i++ ) {
+ for ( i = 0; i < chipset_id_list->count; i++ ) {
printk(TBOOT_DETA"\t\t entry %u:\n", i);
acm_chipset_id_t *chipset_id = &(chipset_id_list->chipset_ids[i]);
printk(TBOOT_DETA"\t\t flags: 0x%x\n", chipset_id->flags);
@@ -389,7 +390,7 @@ static void print_acm_hdr(const acm_hdr_t *hdr, const char *mod_name)
return;
}
printk(TBOOT_DETA"\t\t count: %u\n", proc_id_list->count);
- for ( unsigned int i = 0; i < proc_id_list->count; i++ ) {
+ for ( i = 0; i < proc_id_list->count; i++ ) {
printk(TBOOT_DETA"\t\t entry %u:\n", i);
acm_processor_id_t *proc_id = &(proc_id_list->processor_ids[i]);
printk(TBOOT_DETA"\t\t fms: 0x%x\n", proc_id->fms);
@@ -412,7 +413,7 @@ static void print_acm_hdr(const acm_hdr_t *hdr, const char *mod_name)
printk(TBOOT_DETA"\t\t tpm_family : 0x%x\n", info_list->capabilities.tpm_family);
printk(TBOOT_DETA"\t\t tpm_nv_index_set : 0x%x\n", info_list->capabilities.tpm_nv_index_set);
printk(TBOOT_DETA"\t\t alg count: %u\n", info_list->count);
- for ( unsigned int i = 0; i < info_list->count; i++ ) {
+ for ( i = 0; i < info_list->count; i++ ) {
printk(TBOOT_DETA"\t\t alg_id: 0x%x\n", info_list->alg_id[i]);
}
}
diff --git a/tboot/acpi.c b/tboot/acpi.c
index c2a25a4..846d3e9 100644
--- a/tboot/acpi.c
+++ b/tboot/acpi.c
@@ -169,6 +169,8 @@ struct acpi_rsdp
/* this function can find dmar table whether or not it was hidden */
static struct acpi_table_header *find_table(const char *table_name)
{
+ uint64_t *curr_table_64;
+ uint32_t *curr_table_32;
if ( !find_rsdp() ) {
printk(TBOOT_ERR"no rsdp to use\n");
return NULL;
@@ -179,10 +181,10 @@ static struct acpi_table_header *find_table(const char *table_name)
/* because value will be ignored */
if ( rsdp->rsdp1.revision >= 2 && xsdt != NULL ) { /* ACPI 2.0+ */
- for ( uint64_t *curr_table = (uint64_t*)xsdt->table_offsets;
- curr_table < (uint64_t *)((void *)xsdt + xsdt->hdr.length);
- curr_table++ ) {
- table = (struct acpi_table_header *)(uintptr_t)*curr_table;
+ for ( curr_table_64 = (uint64_t*)xsdt->table_offsets;
+ curr_table_64 < (uint64_t *)((void *)xsdt + xsdt->hdr.length);
+ curr_table_64++ ) {
+ table = (struct acpi_table_header *)(uintptr_t)*curr_table_64;
if ( memcmp(table->signature, table_name,
sizeof(table->signature)) == 0 )
return table;
@@ -196,10 +198,10 @@ static struct acpi_table_header *find_table(const char *table_name)
return NULL;
}
- for ( uint32_t *curr_table = rsdt->table_offsets;
- curr_table < (uint32_t *)((void *)rsdt + rsdt->hdr.length);
- curr_table++ ) {
- table = (struct acpi_table_header *)(uintptr_t)*curr_table;
+ for ( curr_table_32 = rsdt->table_offsets;
+ curr_table_32 < (uint32_t *)((void *)rsdt + rsdt->hdr.length);
+ curr_table_32++ ) {
+ table = (struct acpi_table_header *)(uintptr_t)*curr_table_32;
if ( memcmp(table->signature, table_name,
sizeof(table->signature)) == 0 )
return table;
diff --git a/tboot/cmdline.c b/tboot/cmdline.c
index cee60a5..be55099 100644
--- a/tboot/cmdline.c
+++ b/tboot/cmdline.c
@@ -114,7 +114,8 @@ static const tb_loglvl_map_t g_loglvl_map[] = {
static const char* get_option_val(const cmdline_option_t *options, char vals[][MAX_VALUE_LEN], const char *opt_name)
{
- for ( int i = 0; options[i].name != NULL; i++ ) {
+ int i;
+ for ( i = 0; options[i].name != NULL; i++ ) {
if ( strcmp(options[i].name, opt_name) == 0 )
return vals[i];
}
diff --git a/tboot/com.c b/tboot/com.c
index c1851a6..e65ada4 100644
--- a/tboot/com.c
+++ b/tboot/com.c
@@ -66,13 +66,15 @@ static void comc_putchar(int c)
static void comc_setup(int speed)
{
+ int wait;
+
OUTB(com_cfcr, CFCR_DLAB | g_com_port.comc_fmt);
OUTB(com_dlbl, COMC_BPS(speed) & 0xff);
OUTB(com_dlbh, COMC_BPS(speed) >> 8);
OUTB(com_cfcr, g_com_port.comc_fmt);
OUTB(com_mcr, MCR_RTS | MCR_DTR);
- for ( int wait = COMC_TXWAIT; wait > 0; wait-- ) {
+ for ( wait = COMC_TXWAIT; wait > 0; wait-- ) {
INB(com_data);
if ( !(INB(com_lsr) & LSR_RXRDY) )
break;
diff --git a/tboot/heap.c b/tboot/heap.c
index 0fadb57..02a55d7 100644
--- a/tboot/heap.c
+++ b/tboot/heap.c
@@ -86,16 +86,18 @@ static bool verify_bios_spec_ver_elt(const heap_ext_data_element_t *elt)
static void print_acm_elt(const heap_ext_data_element_t *elt)
{
const heap_acm_elt_t *acm_elt = (const heap_acm_elt_t *)elt->data;
+ unsigned int i;
printk(TBOOT_DETA"\t\t ACM:\n");
printk(TBOOT_DETA"\t\t num_acms: %u\n", acm_elt->num_acms);
- for ( unsigned int i = 0; i < acm_elt->num_acms; i++ )
+ for ( i = 0; i < acm_elt->num_acms; i++ )
printk(TBOOT_DETA"\t\t acm_addrs[%u]: 0x%jx\n", i, acm_elt->acm_addrs[i]);
}
static bool verify_acm_elt(const heap_ext_data_element_t *elt)
{
const heap_acm_elt_t *acm_elt = (const heap_acm_elt_t *)elt->data;
+ unsigned int i;
if ( elt->size != sizeof(*elt) + sizeof(*acm_elt) +
acm_elt->num_acms*sizeof(uint64_t) ) {
@@ -107,7 +109,7 @@ static bool verify_acm_elt(const heap_ext_data_element_t *elt)
if ( acm_elt->num_acms == 0 )
printk(TBOOT_WARN"HEAP_ACM element has no ACM addrs\n");
- for ( unsigned int i = 0; i < acm_elt->num_acms; i++ ) {
+ for ( i = 0; i < acm_elt->num_acms; i++ ) {
if ( acm_elt->acm_addrs[i] == 0 ) {
printk(TBOOT_ERR"HEAP_ACM element ACM addr (%u) is NULL\n", i);
return false;
@@ -292,6 +294,7 @@ void print_event_2(void *evt, uint16_t alg)
static void print_evt_log_ptr_elt_2(const heap_ext_data_element_t *elt)
{
+ unsigned int i;
const heap_event_log_ptr_elt2_t *elog_elt =
(const heap_event_log_ptr_elt2_t *)elt->data;
const heap_event_log_descr_t *log_descr;
@@ -300,7 +303,7 @@ static void print_evt_log_ptr_elt_2(const heap_ext_data_element_t *elt)
printk(TBOOT_DETA"\t\t size: %u\n", elt->size);
printk(TBOOT_DETA"\t\t count: %d\n", elog_elt->count);
- for ( unsigned int i=0; i<elog_elt->count; i++ ) {
+ for ( i=0; i<elog_elt->count; i++ ) {
log_descr = &elog_elt->event_log_descr[i];
printk(TBOOT_DETA"\t\t\t Log Descrption:\n");
printk(TBOOT_DETA"\t\t\t Alg: %u\n", log_descr->alg);
@@ -668,12 +671,13 @@ static bool verify_os_sinit_data(const txt_heap_t *txt_heap)
static void print_sinit_mdrs(const sinit_mdr_t mdrs[], uint32_t num_mdrs)
{
+ unsigned int i;
static const char *mem_types[] = {"GOOD", "SMRAM OVERLAY",
"SMRAM NON-OVERLAY",
"PCIE EXTENDED CONFIG", "PROTECTED"};
printk(TBOOT_DETA"\t sinit_mdrs:\n");
- for ( unsigned int i = 0; i < num_mdrs; i++ ) {
+ for ( i = 0; i < num_mdrs; i++ ) {
printk(TBOOT_DETA"\t\t %016Lx - %016Lx ", mdrs[i].base,
mdrs[i].base + mdrs[i].length);
if ( mdrs[i].mem_type < sizeof(mem_types)/sizeof(mem_types[0]) )
diff --git a/tboot/include/tb_policy.h b/tboot/include/tb_policy.h
index 118a735..3632262 100644
--- a/tboot/include/tb_policy.h
+++ b/tboot/include/tb_policy.h
@@ -174,11 +174,12 @@ static inline size_t calc_policy_entry_size(const tb_policy_entry_t *pol_entry,
static inline size_t calc_policy_size(const tb_policy_t *policy)
{
size_t size = sizeof(*policy);
+ int i;
/* tb_policy_t has empty array, which isn't counted in size */
/* so add size of each policy */
const tb_policy_entry_t *pol_entry = policy->entries;
- for ( int i = 0; i < policy->num_entries; i++ ) {
+ for ( i = 0; i < policy->num_entries; i++ ) {
size_t entry_size = calc_policy_entry_size(pol_entry,
policy->hash_alg);
pol_entry = (void *)pol_entry + entry_size;
@@ -210,6 +211,7 @@ static inline tb_hash_t *get_policy_entry_hash(
static inline tb_policy_entry_t* get_policy_entry(const tb_policy_t *policy,
int i)
{
+ int j;
/* assumes policy has already been validated */
if ( policy == NULL ) {
@@ -223,7 +225,7 @@ static inline tb_policy_entry_t* get_policy_entry(const tb_policy_t *policy,
}
tb_policy_entry_t *pol_entry = (tb_policy_entry_t *)policy->entries;
- for ( int j = 0; j < i; j++ ) {
+ for ( j = 0; j < i; j++ ) {
pol_entry = (void *)pol_entry +
calc_policy_entry_size(pol_entry, policy->hash_alg);
}
@@ -234,6 +236,7 @@ static inline tb_policy_entry_t* get_policy_entry(const tb_policy_t *policy,
static inline tb_policy_entry_t* find_policy_entry(const tb_policy_t *policy,
uint8_t mod_num)
{
+ int i;
/* assumes policy has already been validated */
if ( policy == NULL ) {
@@ -241,7 +244,7 @@ static inline tb_policy_entry_t* find_policy_entry(const tb_policy_t *policy,
return NULL;
}
- for ( int i = 0; i < policy->num_entries; i++ ) {
+ for ( i = 0; i < policy->num_entries; i++ ) {
tb_policy_entry_t *pol_entry = get_policy_entry(policy, i);
if ( pol_entry == NULL )
return NULL;
@@ -259,6 +262,8 @@ static inline tb_policy_entry_t* find_policy_entry(const tb_policy_t *policy,
*/
static inline bool verify_policy(const tb_policy_t *policy, size_t size, bool print)
{
+ int i, j;
+
if ( print ) PRINT(TBOOT_DETA"policy:\n");
if ( policy == NULL ) {
@@ -293,7 +298,7 @@ static inline bool verify_policy(const tb_policy_t *policy, size_t size, bool pr
if ( print ) PRINT(TBOOT_DETA"\t num_entries: %u\n", policy->num_entries);
const tb_policy_entry_t *pol_entry = policy->entries;
- for ( int i = 0; i < policy->num_entries; i++ ) {
+ for ( i = 0; i < policy->num_entries; i++ ) {
/* check header of policy entry */
if ( ((void *)pol_entry - (void *)policy + sizeof(*pol_entry)) >
size ) {
@@ -358,7 +363,7 @@ static inline bool verify_policy(const tb_policy_t *policy, size_t size, bool pr
return false;
}
- for ( int j = 0; j < pol_entry->num_hashes; j++ ) {
+ for ( j = 0; j < pol_entry->num_hashes; j++ ) {
if ( print ) {
PRINT(TBOOT_DETA"\t\t hashes[%d]: ", j);
print_hash(get_policy_entry_hash(pol_entry,
diff --git a/tboot/include/tpm.h b/tboot/include/tpm.h
index 59ebde1..07631c8 100644
--- a/tboot/include/tpm.h
+++ b/tboot/include/tpm.h
@@ -381,12 +381,14 @@ typedef union {
static inline void _read_tpm_reg(int locality, u32 reg, u8 *_raw, size_t size)
{
- for ( size_t i = 0; i < size; i++ ) _raw[i] = readb((TPM_LOCALITY_BASE_N(locality) | reg) + i);
+ size_t i;
+ for ( i = 0; i < size; i++ ) _raw[i] = readb((TPM_LOCALITY_BASE_N(locality) | reg) + i);
}
static inline void _write_tpm_reg(int locality, u32 reg, u8 *_raw, size_t size)
{
- for ( size_t i = 0; i < size; i++ ) writeb((TPM_LOCALITY_BASE_N(locality) | reg) + i, _raw[i]);
+ size_t i;
+ for ( i = 0; i < size; i++ ) writeb((TPM_LOCALITY_BASE_N(locality) | reg) + i, _raw[i]);
}
@@ -398,7 +400,8 @@ static inline void _write_tpm_reg(int locality, u32 reg, u8 *_raw, size_t size)
static inline void _reverse_copy(uint8_t *out, uint8_t *in, uint32_t count)
{
- for ( uint32_t i = 0; i < count; i++ )
+ uint32_t i;
+ for ( i = 0; i < count; i++ )
out[i] = in[count - i - 1];
}
diff --git a/tboot/launch.S b/tboot/launch.S
index 1d244ab..efc9170 100644
--- a/tboot/launch.S
+++ b/tboot/launch.S
@@ -59,7 +59,7 @@
#define BSP_STACK_SIZE 0x4000
#define AP_STACK_SIZE 0x0800
-.section ".text"
+.section .text
.align PAGE_SIZE, 0
.code32
@@ -432,17 +432,17 @@ _mle_size:
_bss_size:
.quad 0x0000000000000000 /* .bss size */
-.section ".data"
+.section .data
.align PAGE_SIZE, 0
-.section ".rdata"
+.section .rdata
.align PAGE_SIZE, 0
/*
* shared data page with kernel (i.e. Xen)
* (put at end so that not split e820 region for tboot)
*/
-.section ".tbootsh","w"
+.section .tbootsh,"w"
.align PAGE_SIZE, 0
.globl _tboot_shared
@@ -450,7 +450,7 @@ _tboot_shared:
.fill PAGE_SIZE,1,0
.align PAGE_SIZE, 0
-.section ".bss"
+.section .bss
.align PAGE_SIZE, 0
.global _bss_start
diff --git a/tboot/misc.c b/tboot/misc.c
index 480e9da..446e7f1 100644
--- a/tboot/misc.c
+++ b/tboot/misc.c
@@ -54,7 +54,8 @@
*/
void print_hex(const char *prefix, const void *prtptr, size_t size)
{
- for ( size_t i = 0; i < size; i++ ) {
+ size_t i;
+ for ( i = 0; i < size; i++ ) {
if ( i % 16 == 0 && prefix != NULL )
printk(TBOOT_DETA"\n%s", prefix);
printk(TBOOT_DETA"%02x ", *(uint8_t *)prtptr++);
diff --git a/tboot/mtrrs.c b/tboot/mtrrs.c
index 0d02b90..f50b31a 100644
--- a/tboot/mtrrs.c
+++ b/tboot/mtrrs.c
@@ -157,6 +157,7 @@ bool set_mtrrs_for_acmod(const acm_hdr_t *hdr)
void save_mtrrs(mtrr_state_t *saved_state)
{
+ unsigned int ndx;
mtrr_cap_t mtrr_cap;
/* IA32_MTRR_DEF_TYPE MSR */
@@ -175,7 +176,7 @@ void save_mtrrs(mtrr_state_t *saved_state)
saved_state->num_var_mtrrs = mtrr_cap.vcnt;
/* physmask's and physbase's */
- for ( unsigned int ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
+ for ( ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
saved_state->mtrr_physmasks[ndx].raw =
rdmsr(MTRR_PHYS_MASK0_MSR + ndx*2);
saved_state->mtrr_physbases[ndx].raw =
@@ -187,12 +188,13 @@ void save_mtrrs(mtrr_state_t *saved_state)
static void print_mtrrs(const mtrr_state_t *saved_state)
{
+ unsigned int i;
printk(TBOOT_DETA"mtrr_def_type: e = %d, fe = %d, type = %x\n",
saved_state->mtrr_def_type.e, saved_state->mtrr_def_type.fe,
saved_state->mtrr_def_type.type );
printk(TBOOT_DETA"mtrrs:\n");
printk(TBOOT_DETA"\t\t base mask type v\n");
- for ( unsigned int i = 0; i < saved_state->num_var_mtrrs; i++ ) {
+ for ( i = 0; i < saved_state->num_var_mtrrs; i++ ) {
printk(TBOOT_DETA"\t\t%13.13Lx %13.13Lx %2.2x %d\n",
(uint64_t)saved_state->mtrr_physbases[i].base,
(uint64_t)saved_state->mtrr_physmasks[i].mask,
@@ -204,6 +206,7 @@ static void print_mtrrs(const mtrr_state_t *saved_state)
/* base should be 4k-bytes aligned, no invalid overlap combination */
static int get_page_type(const mtrr_state_t *saved_state, uint32_t base)
{
+ unsigned int i;
int type = -1;
bool wt = false;
uint64_t maxphyaddr_mask = get_maxphyaddr_mask();
@@ -211,7 +214,7 @@ static int get_page_type(const mtrr_state_t *saved_state, uint32_t base)
/* omit whether the fix mtrrs are enabled, just check var mtrrs */
base >>= PAGE_SHIFT;
- for ( unsigned int i = 0; i < saved_state->num_var_mtrrs; i++ ) {
+ for ( i = 0; i < saved_state->num_var_mtrrs; i++ ) {
const mtrr_physbase_t *base_i = &saved_state->mtrr_physbases[i];
const mtrr_physmask_t *mask_i = &saved_state->mtrr_physmasks[i];
@@ -342,6 +345,7 @@ bool validate_mtrrs(const mtrr_state_t *saved_state)
mtrr_cap_t mtrr_cap;
uint64_t maxphyaddr_mask = get_maxphyaddr_mask();
uint64_t max_pages = maxphyaddr_mask + 1; /* max # 4k pages supported */
+ unsigned int ndx, i;
/* check is meaningless if MTRRs were disabled */
if ( saved_state->mtrr_def_type.e == 0 )
@@ -356,7 +360,7 @@ bool validate_mtrrs(const mtrr_state_t *saved_state)
}
/* variable MTRRs describing non-contiguous memory regions */
- for ( unsigned int ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
+ for ( ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
uint64_t tb;
if ( saved_state->mtrr_physmasks[ndx].v == 0 )
@@ -384,14 +388,14 @@ bool validate_mtrrs(const mtrr_state_t *saved_state)
}
/* overlaping regions with invalid memory type combinations */
- for ( unsigned int ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
+ for ( ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
const mtrr_physbase_t *base_ndx = &saved_state->mtrr_physbases[ndx];
const mtrr_physmask_t *mask_ndx = &saved_state->mtrr_physmasks[ndx];
if ( mask_ndx->v == 0 )
continue;
- for ( unsigned int i = ndx + 1; i < saved_state->num_var_mtrrs; i++ ) {
+ for ( i = ndx + 1; i < saved_state->num_var_mtrrs; i++ ) {
const mtrr_physbase_t *base_i = &saved_state->mtrr_physbases[i];
const mtrr_physmask_t *mask_i = &saved_state->mtrr_physmasks[i];
@@ -464,6 +468,7 @@ bool validate_mtrrs(const mtrr_state_t *saved_state)
void restore_mtrrs(const mtrr_state_t *saved_state)
{
+ unsigned int ndx;
/* called by apply_policy() so use saved ptr */
if ( saved_state == NULL )
saved_state = g_saved_mtrrs;
@@ -475,7 +480,7 @@ void restore_mtrrs(const mtrr_state_t *saved_state)
set_all_mtrrs(false);
/* physmask's and physbase's */
- for ( unsigned int ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
+ for ( ndx = 0; ndx < saved_state->num_var_mtrrs; ndx++ ) {
wrmsr(MTRR_PHYS_MASK0_MSR + ndx*2,
saved_state->mtrr_physmasks[ndx].raw);
wrmsr(MTRR_PHYS_BASE0_MSR + ndx*2,
@@ -494,6 +499,7 @@ bool set_mem_type(const void *base, uint32_t size, uint32_t mem_type)
{
int num_pages;
int ndx;
+ int j;
mtrr_def_type_t mtrr_def_type;
mtrr_cap_t mtrr_cap;
mtrr_physmask_t mtrr_physmask;
@@ -540,7 +546,7 @@ bool set_mem_type(const void *base, uint32_t size, uint32_t mem_type)
base_v = base_v >>1 ;
}
- for (int j=i-12; j>0; j--) mtrr_s =mtrr_s*2; //mtrr_s = mtrr_s << 1
+ for (j=i-12; j>0; j--) mtrr_s =mtrr_s*2; //mtrr_s = mtrr_s << 1
printk(TBOOT_DETA"The maximum allowed MTRR range size=%d Pages \n", mtrr_s);
while (num_pages >= mtrr_s){
diff --git a/tboot/policy.c b/tboot/policy.c
index 3c4d7d1..42ceb39 100644
--- a/tboot/policy.c
+++ b/tboot/policy.c
@@ -252,6 +252,7 @@ static bool read_policy_from_tpm(uint32_t index, void* policy_index, size_t *pol
*/
static bool unwrap_lcp_policy(void)
{
+ int i;
void* lcp_base;
uint32_t lcp_size;
const efi_file_t *lcp;
@@ -280,7 +281,7 @@ static bool unwrap_lcp_policy(void)
lcp_policy_data_t *poldata = (lcp_policy_data_t *)lcp_base;
lcp_policy_list_t *pollist = &poldata->policy_lists[0];
- for ( int i = 0; i < poldata->num_lists; i++ ) {
+ for ( i = 0; i < poldata->num_lists; i++ ) {
lcp_policy_element_t *elt = pollist->policy_elements;
uint32_t elts_size = 0;
@@ -406,6 +407,7 @@ static bool hash_module(hash_list_t *hl,
const char* cmdline, void *base,
size_t size)
{
+ unsigned i,j,k;
if ( hl == NULL ) {
printk(TBOOT_ERR"Error: input parameter is wrong.\n");
return false;
@@ -453,8 +455,8 @@ static bool hash_module(hash_list_t *hl,
if ( !g_tpm->hash(g_tpm, 2, base, size, &img_hl) )
return false;
- for (unsigned int i=0; i<hl->count; i++) {
- for (unsigned int j=0; j<img_hl.count; j++) {
+ for (i=0; i<hl->count; i++) {
+ for (j=0; j<img_hl.count; j++) {
if (hl->entries[i].alg == img_hl.entries[j].alg) {
copy_hash((tb_hash_t *)buf, &hl->entries[i].hash,
hl->entries[i].alg);
@@ -464,7 +466,7 @@ static bool hash_module(hash_list_t *hl,
2*get_hash_size(hl->entries[i].alg), &final_hl) )
return false;
- for (unsigned int k=0; k<final_hl.count; k++) {
+ for (k=0; k<final_hl.count; k++) {
if (hl->entries[i].alg == final_hl.entries[k].alg) {
copy_hash(&hl->entries[i].hash,
&final_hl.entries[k].hash,
@@ -485,7 +487,7 @@ static bool hash_module(hash_list_t *hl,
{
tb_hash_t img_hash;
hl->count = g_tpm->alg_count;
- for (unsigned int i=0; i<hl->count; i++) {
+ for (i=0; i<hl->count; i++) {
hl->entries[i].alg = g_tpm->algs[i];
if ( !hash_buffer((const unsigned char *)cmdline, strlen(cmdline),
&hl->entries[i].hash, g_tpm->algs[i]) )
@@ -510,6 +512,7 @@ static bool hash_module(hash_list_t *hl,
static bool is_hash_in_policy_entry(const tb_policy_entry_t *pol_entry,
tb_hash_t *hash, uint16_t hash_alg)
{
+ int i;
/* assumes policy entry has been validated */
if ( pol_entry == NULL || hash == NULL) {
@@ -520,7 +523,7 @@ static bool is_hash_in_policy_entry(const tb_policy_entry_t *pol_entry,
if ( pol_entry->hash_type == TB_HTYPE_ANY )
return true;
else if ( pol_entry->hash_type == TB_HTYPE_IMAGE ) {
- for ( int i = 0; i < pol_entry->num_hashes; i++ ) {
+ for ( i = 0; i < pol_entry->num_hashes; i++ ) {
if ( are_hashes_equal(get_policy_entry_hash(pol_entry, hash_alg,
i), hash, hash_alg) )
return true;
@@ -535,15 +538,16 @@ static bool is_hash_in_policy_entry(const tb_policy_entry_t *pol_entry,
*/
static tb_policy_action_t evaluate_error(tb_error_t error)
{
+ unsigned i,j;
tb_policy_action_t action = TB_POLACT_HALT;
if ( error == TB_ERR_NONE )
return TB_POLACT_CONTINUE;
- for ( unsigned int i = 0; i < ARRAY_SIZE(g_policy_map); i++ ) {
+ for ( i = 0; i < ARRAY_SIZE(g_policy_map); i++ ) {
if ( g_policy_map[i].policy_type == g_policy->policy_type ) {
action = g_policy_map[i].default_action;
- for ( unsigned int j = 0;
+ for ( j = 0;
j < ARRAY_SIZE(g_policy_map[i].exception_action_table);
j++ ) {
if ( g_policy_map[i].exception_action_table[j].error ==
@@ -665,6 +669,7 @@ static tb_error_t verify_module(void *base, size_t size,
static void verify_g_policy(void)
{
+ int i;
/* assumes mbi is valid */
printk(TBOOT_INFO"verifying policy \n");
@@ -701,7 +706,7 @@ static void verify_g_policy(void)
case TB_EXTPOL_EMBEDDED:
{
VL_ENTRIES(NUM_VL_ENTRIES).hl.count = g_tpm->alg_count;
- for (int i=0; i<g_tpm->alg_count; i++) {
+ for (i=0; i<g_tpm->alg_count; i++) {
VL_ENTRIES(NUM_VL_ENTRIES).hl.entries[i].alg = g_tpm->algs[i];
if ( !hash_buffer(buf, size, &VL_ENTRIES(NUM_VL_ENTRIES).hl.entries[i].hash,
g_tpm->algs[i]) )
@@ -741,12 +746,13 @@ void verify_all_modules(void)
static int find_first_nvpolicy_entry(const tb_policy_t *policy)
{
+ int i;
if ( policy == NULL ) {
PRINT(TBOOT_ERR"Error: policy pointer is NULL\n");
return -1;
}
- for ( int i = 0; i < policy->num_entries; i++ ) {
+ for ( i = 0; i < policy->num_entries; i++ ) {
tb_policy_entry_t *pol_entry = get_policy_entry(policy, i);
if ( pol_entry == NULL )
return -1;
@@ -785,6 +791,7 @@ static tb_error_t verify_nvindex(tb_policy_entry_t *pol_entry,
size_t nv_size = sizeof(nv_buf);
tb_hash_t digest;
uint32_t attribute;
+ int i;
if ( pol_entry == NULL )
return TB_ERR_NV_VERIFICATION_FAILED;
@@ -859,8 +866,9 @@ static tb_error_t verify_nvindex(tb_policy_entry_t *pol_entry,
void verify_all_nvindices(void)
{
+ int i;
/* go through nv policies in tb policy */
- for ( int i = find_first_nvpolicy_entry(g_policy);
+ for ( i = find_first_nvpolicy_entry(g_policy);
i >= 0;
i = find_next_nvpolicy_entry(g_policy, i) ) {
tb_policy_entry_t *pol_entry = get_policy_entry(g_policy, i);
diff --git a/tboot/tpm_12.c b/tboot/tpm_12.c
index 6e326d1..3d5da55 100644
--- a/tboot/tpm_12.c
+++ b/tboot/tpm_12.c
@@ -896,7 +896,8 @@ static uint32_t _tpm12_unseal(uint32_t locality, tpm_key_handle_t hkey,
}
#define XOR_BLOB_TYPE(data, pad) {\
- for ( uint32_t i = 0; i < sizeof(*(data)); i++ ) \
+ uint32_t i; \
+ for ( i = 0; i < sizeof(*(data)); i++ ) \
((uint8_t *)data)[i] ^= ((uint8_t *)pad)[i % sizeof(*(pad))];\
}
diff --git a/tboot/tpm_20.c b/tboot/tpm_20.c
index 87007d0..45c4a6b 100644
--- a/tboot/tpm_20.c
+++ b/tboot/tpm_20.c
@@ -2199,13 +2199,14 @@ static uint32_t tpm20_save_state(struct tpm_if *ti, uint32_t locality)
static bool tpm20_cap_pcrs(struct tpm_if *ti, u32 locality, int pcr)
{
bool was_capped[TPM_NR_PCRS] = {false};
+ unsigned int i;
hash_list_t cap_val; /* use whatever val is on stack */
if ( ti == NULL || locality >= TPM_NR_LOCALITIES || pcr == 0 )
return false;
cap_val.count = ti->banks;
- for (unsigned int i=0; i<ti->banks; i++)
+ for (i=0; i<ti->banks; i++)
cap_val.entries[i].alg = ti->algs_banks[i];
if (pcr >= 0) {
@@ -2235,7 +2236,8 @@ static bool tpm20_cap_pcrs(struct tpm_if *ti, u32 locality, int pcr)
static bool alg_is_supported(u16 alg)
{
- for (int i=0; i<2; i++) {
+ int i;
+ for (i=0; i<2; i++) {
if (alg == tboot_alg_list[i])
return true;
}
@@ -2319,7 +2321,7 @@ static bool tpm20_init(struct tpm_if *ti)
}
}
printk(TBOOT_INFO"TPM: supported alg count = %08X\n", ti->alg_count);
- for (unsigned int i=0; i<ti->alg_count; i++)
+ for (i=0; i<ti->alg_count; i++)
printk(TBOOT_INFO"\t\t %08X\n", ti->algs[i]);
if (handle2048 != 0)
diff --git a/tboot/txt.c b/tboot/txt.c
index 3f7dcf1..3cafd68 100644
--- a/tboot/txt.c
+++ b/tboot/txt.c
@@ -561,6 +561,7 @@ bool txt_prepare_cpu(void)
{
unsigned long cr0;
uint64_t mcg_cap, mcg_stat, msr_efer, rflags;
+ unsigned int i;
/* must be running at CPL 0 => this is implicit in even getting this far */
/* since our bootstrap code loads a GDT, etc. */
@@ -631,7 +632,7 @@ bool txt_prepare_cpu(void)
/* check if all machine check regs are clear */
mcg_cap = rdmsr(MSR_MCG_CAP);
- for ( unsigned int i = 0; i < (mcg_cap & 0xff); i++ ) {
+ for ( i = 0; i < (mcg_cap & 0xff); i++ ) {
mcg_stat = rdmsr(MSR_MC0_STATUS + 4*i);
if ( mcg_stat & (1ULL << 63) ) {
printk(TBOOT_ERR"MCG[%u] = %Lx ERROR\n", i, mcg_stat);
diff --git a/tboot/vga.c b/tboot/vga.c
index 8ddc2f5..19e99f3 100644
--- a/tboot/vga.c
+++ b/tboot/vga.c
@@ -61,12 +61,13 @@ static inline void reset_screen(void)
static void scroll_screen(void)
{
- for ( long long y = 1; y < MAX_LINES; y++ ) {
- for ( long long x = 0; x < MAX_COLS; x++ )
+ long long x,y;
+ for ( y = 1; y < MAX_LINES; y++ ) {
+ for ( x = 0; x < MAX_COLS; x++ )
writew(VGA_ADDR(x, y-1), readw(VGA_ADDR(x, y)));
}
/* clear last line */
- for ( long long x = 0; x < MAX_COLS; x++ )
+ for ( x = 0; x < MAX_COLS; x++ )
writew(VGA_ADDR(x, MAX_LINES-1), 0x720);
}
diff --git a/tboot/vmac.c b/tboot/vmac.c
index be234ed..f44dce7 100644
--- a/tboot/vmac.c
+++ b/tboot/vmac.c
@@ -17,8 +17,9 @@
#include <efibase.h>
#include <types.h>
#include <vmac.h>
-/*#define UINT64_C(x) x##ULL*/
-/* end for tboot */
+#ifndef UINT64_C
+#define UINT64_C(x) x##ULL
+#endif
/* Enable code tuned for 64-bit registers; otherwise tuned for 32-bit */
#ifndef VMAC_ARCH_64
diff --git a/tboot/vsprintf.c b/tboot/vsprintf.c
index a100cc0..cc7d488 100644
--- a/tboot/vsprintf.c
+++ b/tboot/vsprintf.c
@@ -93,7 +93,8 @@ static unsigned long write_pads_to_buffer(char *buf, size_t buf_len,
unsigned long buf_pos, char pad,
size_t pad_len)
{
- for ( unsigned int i = 0; i < pad_len; i++ )
+ unsigned int i;
+ for ( i = 0; i < pad_len; i++ )
buf_pos = write_char_to_buffer(buf, buf_len, buf_pos, pad);
return buf_pos;