aboutsummaryrefslogtreecommitdiff
path: root/lib/libtpm/tpm.code
blob: 05f4547ea24f890b2c997555befa18e0dff7bad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/******************************************************************************
 * Copyright (c) 2015-2020 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/
/*
 * libtpm bindings for SLOF - implementation
 */

#include <tcgbios.h>
#include <stdbool.h>

/************************************************/
/* Startup TPM code                             */
/* SLOF:   tpm-start  ( -- errcode )            */
/* LIBTPM: tpm_start(void)                      */
/************************************************/
PRIM(tpm_X2d_start)
	PUSH;
	TOS.n = tpm_start();
MIRP

/************************************************/
/* Shutdown TPM layer before OS takes over      */
/* SLOF:   tpm-finalize  ( -- )                 */
/* LIBTPM: tpm_finalize(void)                   */
/************************************************/
PRIM(tpm_X2d_finalize)
	tpm_finalize();
MIRP

/***************************************************************/
/* Prepare TPM state for bootloader                            */
/* SLOF:   tpm-leave-firwmare  ( -- errcode )                  */
/* LIBTPM: tpm_leave_firmware(void)                            */
/***************************************************************/
PRIM(tpm_X2d_leave_X2d_firmware)
	PUSH;
	TOS.n = tpm_leave_firmware();
MIRP

/*************************************************************/
/* Convey log address and size                               */
/* SLOF:   tpm-set-log-parameters  ( addr size -- )          */
/* LIBTPM: tpm_set_log_parameters(void *addr, uint64_t size) */
/*************************************************************/
PRIM(tpm_X2d_set_X2d_log_X2d_parameters)
	int size = TOS.u; POP;
	void *addr = TOS.a; POP;
	tpm_set_log_parameters(addr, size);
MIRP

/*********************************************************/
/* Firmware API                                          */
/* SLOF:   tpm-driver-get_failure-reason ( -- errcode)   */
/* LIBTPM: errcode = tpm_driver_get_failure_reason(void) */
/*********************************************************/
PRIM(tpm_X2d_driver_X2d_get_X2d_failure_X2d_reason)
	PUSH;
	TOS.n = tpm_driver_get_failure_reason();
MIRP

/********************************************************/
/* Firmware API                                         */
/* SLOF:   tpm-driver-set-failure_reason ( errcode -- ) */
/* LIBTPM: tpm_driver_set_failure_reason(errcode)       */
/********************************************************/
PRIM(tpm_X2d_driver_X2d_set_X2d_failure_X2d_reason)
	int errcode = TOS.u; POP;
	tpm_driver_set_failure_reason(errcode);
MIRP

/************************************************/
/* Get the size of the log                      */
/* SLOF:   tpm-get-logsize         ( -- size )  */
/* LIBTPM: logsize = tpm_get_logsize(void)      */
/************************************************/
PRIM(tpm_X2d_get_X2d_logsize)
	PUSH;
	TOS.n = tpm_get_logsize();
MIRP

/**********************************************************************/
/* Measure and log event separators                                   */
/* SLOF:   tpm-add-event-separators  ( start-pcr end-pcr -- errcode)  */
/* LIBTPM: errcode = tpm_add_event_separators(start_pcr, end_pcr)     */
/**********************************************************************/
PRIM(tpm_X2d_add_X2d_event_X2d_separators)
	int end_pcr = TOS.u; POP;
	int start_pcr = TOS.u;
	TOS.n = tpm_add_event_separators(start_pcr, end_pcr);
MIRP

/*************************************************************************/
/* Measure and log boot connect vector (bcv) device's master boot record */
/* SLOF:   tpm-measure-bcv-mbr  ( bootdrv addr length -- errcode )       */
/* LIBTPM: errcode = tpm_measure_bcv_mbr(bbotdrv, addr, length)          */
/*************************************************************************/
PRIM(tpm_X2d_measure_X2d_bcv_X2d_mbr)
	int length = TOS.u; POP;
	void *addr = TOS.a; POP;
	int bootdrv = TOS.u;
	TOS.n = tpm_measure_bcv_mbr(bootdrv, addr, length);
MIRP

/************************************************/
/* Check whether the TPM is working             */
/* SLOF:   tpm-is-working  ( -- true | false )  */
/* LIBTPM: bool = tpm_is_working()              */
/************************************************/
PRIM(tpm_X2d_is_X2d_working)
	PUSH;
	TOS.n = tpm_is_working();
MIRP

/************************************************/
/* Have the S-CRTM measured                     */
/* SLOF:   tpm-measure-scrtm  ( -- errcode )    */
/* LIBTPM: errcode = tpm_measure_scrtm          */
/************************************************/
PRIM(tpm_X2d_measure_X2d_scrtm)
	PUSH;
	TOS.n = tpm_measure_scrtm();
MIRP