ia64/xen-unstable

changeset 14415:aa6914c527e1

TCGBIOS fixes and cleanups.

- Add a missing break into the switch statement
- Simplify the code that switches from protected mode into real mode
by letting it spill eax; this also fixes the case where the stack is
above 0xffff.
- reformat the source for 80 columns
- remove some comments that were relevant when the TCG extensions were
direct part of the real-mode Bochs BIOS

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kfraser@localhost.localdomain
date Thu Mar 15 10:36:10 2007 +0000 (2007-03-15)
parents e9ef0808c09f
children 5bc5ed857cc6
files tools/firmware/rombios/32bit/tcgbios/tcgbios.c tools/firmware/rombios/32bitgateway.c tools/firmware/rombios/tcgbios.c
line diff
     1.1 --- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Thu Mar 15 10:33:32 2007 +0000
     1.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Thu Mar 15 10:36:10 2007 +0000
     1.3 @@ -95,13 +95,15 @@ struct ptti_cust *TCG_CommandList[] = {
     1.4  };
     1.5  
     1.6  /* local function prototypes */
     1.7 -static void sha1(const unsigned char *data, uint32_t length, unsigned char *hash);
     1.8 +static void sha1(const unsigned char *data, uint32_t length,
     1.9 +                 unsigned char *hash);
    1.10  static uint32_t TCG_ShutdownPreBootInterface(uint32_t ebx);
    1.11  static uint32_t HashAll32(struct hai *hai, unsigned char *hash,
    1.12                            uint32_t magic, uint32_t ecx, uint32_t edx);
    1.13  static uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s,
    1.14                                       struct hleeo *hleeo,
    1.15 -                                     uint32_t magic, uint32_t ecx, uint32_t edx);
    1.16 +                                     uint32_t magic, uint32_t ecx,
    1.17 +                                     uint32_t edx);
    1.18  static uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo,
    1.19                                 uint32_t ebx, uint32_t ecx, uint32_t edx);
    1.20  static uint32_t PassThroughToTPM32(struct pttti *pttti, struct pttto *pttto,
    1.21 @@ -181,8 +183,7 @@ uint32_t MA_InitTPM(uint16_t startupcode
    1.22  }
    1.23  
    1.24  static
    1.25 -uint32_t MA_Transmit(unsigned char *cmdbuffer,
    1.26 -                     unsigned char *respbuffer,
    1.27 +uint32_t MA_Transmit(unsigned char *cmdbuffer, unsigned char *respbuffer,
    1.28                       uint32_t respbufferlen)
    1.29  {
    1.30  	uint32_t rc = 0;
    1.31 @@ -289,15 +290,14 @@ void tcpa_acpi_init(void)
    1.32  		uint32_t ctr = 0;
    1.33  		/* get RSDT from RSDP */
    1.34  		rsdt   = (struct acpi_20_rsdt *)rsdp->rsdt_address;
    1.35 -		/* rsdt may be anywhere in 32bit space */
    1.36  		length = rsdt->header.length;
    1.37  		off = 36;
    1.38  		while ((off + 3) < length) {
    1.39  			/* try all pointers to structures */
    1.40  			tcpa = (struct acpi_20_tcpa *)rsdt->entry[ctr];
    1.41  			/* valid TCPA ACPI table ? */
    1.42 -			if (ACPI_2_0_TCPA_SIGNATURE == tcpa->header.signature &&
    1.43 -			    acpi_validate_entry(&tcpa->header) == 0) {
    1.44 +			if (ACPI_2_0_TCPA_SIGNATURE == tcpa->header.signature
    1.45 +			    && acpi_validate_entry(&tcpa->header) == 0) {
    1.46  				found = 1;
    1.47  				break;
    1.48  			}
    1.49 @@ -311,7 +311,6 @@ void tcpa_acpi_init(void)
    1.50  		tcpa = 0;
    1.51  	}
    1.52  
    1.53 -	/* initialize the TCPA part of the EBDA with our data */
    1.54  	tcpa_acpi.tcpa_ptr = tcpa;
    1.55  	tcpa_acpi.lasa_last_ptr = 0;
    1.56  	tcpa_acpi.entry_count = 0;
    1.57 @@ -748,9 +747,7 @@ void tcpa_measure_post(Bit32u from, Bit3
    1.58  }
    1.59  
    1.60  static
    1.61 -uint32_t SendCommand32(uint32_t idx,
    1.62 -                     struct pttto *pttto,
    1.63 -                     uint32_t size_ptto)
    1.64 +uint32_t SendCommand32(uint32_t idx, struct pttto *pttto, uint32_t size_ptto)
    1.65  {
    1.66  	uint32_t rc = 0;
    1.67  	struct pttti *pttti = (struct pttti *)TCG_CommandList[idx];
    1.68 @@ -796,7 +793,8 @@ uint32_t tcpa_initialize_tpm(uint32_t ph
    1.69  	uint32_t pttto_size = sizeof(_pttto);
    1.70  
    1.71  	if (rc == 0) {
    1.72 -		rc = SendCommand32(IDX_CMD_TPM_Startup_0x01, pttto, pttto_size);
    1.73 +		rc = SendCommand32(IDX_CMD_TPM_Startup_0x01, pttto,
    1.74 +		                   pttto_size);
    1.75  	}
    1.76  
    1.77  	if (rc == 0 && physpres != 0) {
    1.78 @@ -884,11 +882,8 @@ uint32_t _TCG_TPM_Extend(unsigned char *
    1.79  
    1.80  
    1.81  static
    1.82 -uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s,
    1.83 -                            struct hleeo *hleeo,
    1.84 -                            uint32_t magic,
    1.85 -                            uint32_t ecx,
    1.86 -                            uint32_t edx)
    1.87 +uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s, struct hleeo *hleeo,
    1.88 +                              uint32_t magic, uint32_t ecx, uint32_t edx)
    1.89  {
    1.90  	uint32_t rc = 0;
    1.91  	uint16_t size;
    1.92 @@ -978,11 +973,8 @@ uint32_t HashLogExtendEvent32(struct hle
    1.93  
    1.94  
    1.95  static
    1.96 -uint32_t PassThroughToTPM32(struct pttti *pttti,
    1.97 -                          struct pttto *pttto,
    1.98 -                          uint32_t magic,
    1.99 -                          uint32_t ecx,
   1.100 -                          uint32_t edx)
   1.101 +uint32_t PassThroughToTPM32(struct pttti *pttti, struct pttto *pttto,
   1.102 +                            uint32_t magic, uint32_t ecx, uint32_t edx)
   1.103  {
   1.104  	uint32_t rc = 0;
   1.105  	uint8_t *cmd32;
   1.106 @@ -1047,9 +1039,7 @@ uint32_t TCG_ShutdownPreBootInterface(ui
   1.107  
   1.108  static
   1.109  uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo,
   1.110 -                      uint32_t ebx,
   1.111 -                      uint32_t ecx,
   1.112 -                      uint32_t edx)
   1.113 +                        uint32_t ebx, uint32_t ecx, uint32_t edx)
   1.114  {
   1.115  	uint32_t rc = 0;
   1.116  	uint16_t size;
   1.117 @@ -1144,9 +1134,7 @@ uint32_t HashLogEvent32(struct hlei *hle
   1.118  
   1.119  static
   1.120  uint32_t HashAll32(struct hai *hai, unsigned char *hash,
   1.121 -                 uint32_t magic,
   1.122 -                 uint32_t ecx,
   1.123 -                 uint32_t edx)
   1.124 +                   uint32_t magic, uint32_t ecx, uint32_t edx)
   1.125  {
   1.126  	uint32_t rc = 0;
   1.127  
   1.128 @@ -1187,9 +1175,7 @@ uint32_t HashAll32(struct hai *hai, unsi
   1.129  
   1.130  static
   1.131  uint32_t TSS32(struct ti *ti, struct to *to,
   1.132 -             uint32_t ebx,
   1.133 -             uint32_t ecx,
   1.134 -             uint32_t edx)
   1.135 +               uint32_t ebx, uint32_t ecx, uint32_t edx)
   1.136  {
   1.137  	uint32_t rc = 0;
   1.138  	if (TCG_IsShutdownPreBootInterface() == 0) {
   1.139 @@ -1209,11 +1195,11 @@ uint32_t TSS32(struct ti *ti, struct to 
   1.140  
   1.141  static
   1.142  uint32_t CompactHashLogExtendEvent32(unsigned char *buffer,
   1.143 -                                   uint32_t info,
   1.144 -                                   uint32_t magic,
   1.145 -                                   uint32_t length,
   1.146 -                                   uint32_t pcrindex,
   1.147 -                                   uint32_t *edx_ptr)
   1.148 +                                     uint32_t info,
   1.149 +                                     uint32_t magic,
   1.150 +                                     uint32_t length,
   1.151 +                                     uint32_t pcrindex,
   1.152 +                                     uint32_t *edx_ptr)
   1.153  {
   1.154  	uint32_t rc = 0;
   1.155  	struct hleeo hleeo;
   1.156 @@ -1356,9 +1342,7 @@ void sha1_do(sha1_ctx *ctx, const unsign
   1.157  
   1.158  	/* treat data in 64-byte chunks */
   1.159  	for (offset = 0; length - offset >= 64; offset += 64) {
   1.160 -		/* copy into the 'w' array */
   1.161  		memcpy(w, data32 + offset, 64);
   1.162 -		/* hash the block in the 'w' array */
   1.163  		sha1_block((uint32_t *)w, ctx);
   1.164  		bits += (64 * 8);
   1.165  	}
   1.166 @@ -1408,7 +1392,8 @@ void sha1(const unsigned char *data, uin
   1.167  }
   1.168  
   1.169  
   1.170 -uint32_t TCGInterruptHandler(pushad_regs_t *regs, uint32_t esds, uint32_t flags_ptr)
   1.171 +uint32_t TCGInterruptHandler(pushad_regs_t *regs, uint32_t esds,
   1.172 +                             uint32_t flags_ptr)
   1.173  {
   1.174  	uint16_t DS = esds >> 16;
   1.175  	uint16_t ES = esds & 0xffff;
   1.176 @@ -1435,7 +1420,6 @@ uint32_t TCGInterruptHandler(pushad_regs
   1.177  			}
   1.178  		}
   1.179  		break;
   1.180 -
   1.181  	case 0x01:
   1.182  		regs->u.r32.eax =
   1.183  			HashLogExtendEvent32((struct hleei_short*)
     2.1 --- a/tools/firmware/rombios/32bitgateway.c	Thu Mar 15 10:33:32 2007 +0000
     2.2 +++ b/tools/firmware/rombios/32bitgateway.c	Thu Mar 15 10:36:10 2007 +0000
     2.3 @@ -153,26 +153,17 @@ realmode_gdtdesc:				;to be used in real
     2.4  
     2.5  switch_to_realmode:
     2.6      ; Implementation of switching from protected mode to real mode
     2.7 -    ; restores all registers and prepares cs, es, ds, ss to be used
     2.8 -    ; in real mode
     2.9 +    ; prepares cs, es, ds, ss to be used in real mode
    2.10 +    ; spills   eax
    2.11      START_PM_CODE
    2.12  
    2.13      ; need to fix up the stack to return in 16 bit mode
    2.14      ; currently the 32 bit return address is on the stack
    2.15 -    push bp					;pop@A1
    2.16 -    mov bp, sp
    2.17 -    push eax					;pop@X
    2.18 +    pop eax
    2.19 +    push ax
    2.20  
    2.21 -    mov eax, [bp]				; return address low 16bits
    2.22 -                  				; and 'bp' are being moved
    2.23 -    mov 2[bp], eax
    2.24 -
    2.25 -    pop eax					;@X
    2.26 -    add sp, #2					; adjust stack for 'lost' bytes
    2.27 -
    2.28 -    push eax					;pop@1
    2.29 -    push bx					;pop@2
    2.30 -    push si					;pop@3
    2.31 +    push bx					;pop@1
    2.32 +    push si					;pop@2
    2.33  
    2.34      call _ebda_ss_offset32			; get the offset of the ss
    2.35      mov bx, ax					; entry within the ebda.
    2.36 @@ -229,10 +220,8 @@ switch_to_realmode_goon_2:
    2.37  
    2.38      sti						; allow interrupts
    2.39  
    2.40 -    pop si					;@3
    2.41 -    pop bx					;@2
    2.42 -    pop eax					;@1
    2.43 -    pop bp					;@A1
    2.44 +    pop si					;@2
    2.45 +    pop bx					;@1
    2.46  
    2.47      ret
    2.48  
     3.1 --- a/tools/firmware/rombios/tcgbios.c	Thu Mar 15 10:33:32 2007 +0000
     3.2 +++ b/tools/firmware/rombios/tcgbios.c	Thu Mar 15 10:36:10 2007 +0000
     3.3 @@ -228,6 +228,8 @@ int1a_function32(regs, ES, DS, FLAGS)
     3.4  {
     3.5  	Bit16u rc;
     3.6  
     3.7 +	BX_DEBUG_INT1A("int1a_32: AX=%04x\n", regs.u.r16.ax);
     3.8 +
     3.9  	switch (regs.u.r8.ah) {
    3.10  	case 0xbb:
    3.11  		/*
    3.12 @@ -256,8 +258,10 @@ int1a_function32(regs, ES, DS, FLAGS)
    3.13  		default:
    3.14  			SET_CF();
    3.15  		}
    3.16 +		break;
    3.17  	default:
    3.18  		SET_CF();
    3.19  		break;
    3.20  	}
    3.21 +	BX_DEBUG_INT1A("int1a_32: FLAGS=%04x\n", FLAGS);
    3.22  }