source: trunk/kernel/kern/printk.h @ 624

Last change on this file since 624 was 623, checked in by alain, 6 years ago

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File size: 8.5 KB
Line 
1/*
2 * printk.h - Kernel Log & debug messages API definition.
3 *
4 * authors  Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24///////////////////////////////////////////////////////////////////////////////////
25// The printk.c and printk.h files define the functions used by the kernel
26// to display messages on the kernel terminal TXT0, using a busy waiting policy.
27// It calls synchronously the TXT0 driver, without descheduling.
28///////////////////////////////////////////////////////////////////////////////////
29
30#ifndef _PRINTK_H
31#define _PRINTK_H
32
33#include <hal_kernel_types.h>
34#include <stdarg.h>
35
36#include <hal_special.h> 
37
38/**********************************************************************************
39 * This function build a formatted string.
40 * The supported formats are defined below :
41 *   %b : exactly 2 digits hexadecimal integer (8 bits)
42 *   %c : single ascii character (8 bits)
43 *   %d : up to 10 digits decimal integer (32 bits)
44 *   %u : up to 10 digits unsigned decimal (32 bits)
45 *   %x : up to 8 digits hexadecimal integer (32 bits)
46 *   %X : exactly 8 digits hexadecimal integer (32 bits)
47 *   %l : up to 16 digits hexadecimal integer (64 bits)
48 *   %L : exactly 16 digits hexadecimal integer (64 bits)
49 *   %s : NUL terminated character string
50 **********************************************************************************
51 * @ string     : pointer on target buffer (allocated by caller).
52 * @ length     : target buffer length (number of bytes).
53 * @ format     : format respecting the printf syntax.
54 * @ returns the string length (including NUL) if success / return -1 if error.
55 *********************************************************************************/
56uint32_t snprintf( char     * string,
57                   uint32_t   length,
58                   char     * format, ... );
59
60/**********************************************************************************
61 * This function displays a formatted string on the kernel terminal TXT0,
62 * after taking the TXT0 lock.
63 * It uses a busy waiting policy, calling directly the relevant TXT driver,
64 **********************************************************************************
65 * @ format     : formatted string.
66 *********************************************************************************/
67void printk( char* format, ... );
68
69/**********************************************************************************
70 * This function displays a formatted string on the kernel terminal TXT0,
71 * without taking the TXT0 lock.
72 * It uses a busy waiting policy, calling directly the relevant TXT driver,
73 **********************************************************************************
74 * @ format     : formatted string.
75 *********************************************************************************/
76void nolock_printk( char* format, ... );
77
78
79/**********************************************************************************
80 * This function is called in case of kernel panic. It printt a detailed message
81 * on the TXT0 terminal after taking the TXT0 lock, and call the hal_core_sleep()
82 * function to block the calling core.  It is used by the assert macro (below).
83 **********************************************************************************
84 * @ file_name     : File where the assert macro was invoked
85 * @ function_name : Name of the calling function.
86 * @ line          : Line number where the assert macro was invoked
87 * @ cycle         : Cycle where the macro was invoked
88 * @ format        : Formatted string
89 * ...             : arguments of the format string
90 *
91 * See assert macro documentation for information about printed information.
92 *********************************************************************************/
93void panic( const char * function_name,
94            uint32_t     line,
95            cycle_t      cycle,
96            const char * format,
97            ... ) __attribute__((__noreturn__));
98
99/**********************************************************************************
100 * This macro displays a formated message on kernel TXT0 terminal,
101 * and forces the calling core in sleeping mode if a Boolean condition is false.
102 * Actually used to debug the kernel.
103 *
104 * Extra information printed by assert:
105 * - Current thread, process, and core
106 * - Function name / line number in file / cycle
107 **********************************************************************************
108 * @ condition     : condition that must be true.
109 * @ format        : formatted string
110 *********************************************************************************/
111#define assert( expr, format, ... )                                               \
112{                                                                                 \
113    uint32_t __line_at_expansion = __LINE__;                                      \
114    const volatile cycle_t __assert_cycle = hal_get_cycles();                     \
115    if ( ( expr ) == false )                                                      \
116    {                                                                             \
117        panic( __FUNCTION__,                                                      \
118               __line_at_expansion,                                               \
119               __assert_cycle,                                                    \
120               ( format ), ##__VA_ARGS__ );                                       \
121    }                                                                             \
122}
123
124/**********************************************************************************
125 * This function displays a non-formated message on kernel TXT0 terminal.
126 * This function is actually used to debug the assembly level kernel functions.
127 **********************************************************************************
128 * @ string   : non-formatted string.
129 *********************************************************************************/
130void puts( char * string );
131
132/**********************************************************************************
133 * This function displays a 32 bits value in hexadecimal on kernel TXT0 terminal.
134 * This function is actually used to debug the assembly level kernel functions.
135 **********************************************************************************
136 * @ val   : 32 bits unsigned value.
137 *********************************************************************************/
138void putx( uint32_t val );
139
140/**********************************************************************************
141 * This function displays a 64 bits value in hexadecimal on kernel TXT0 terminal.
142 * This function is actually used to debug the assembly level kernel functions.
143 **********************************************************************************
144 * @ val   : 64 bits unsigned value.
145 *********************************************************************************/
146void putl( uint64_t val );
147
148/**********************************************************************************
149 * This debug function displays on the kernel TXT0 terminal the content of an
150 * array of bytes defined by <buffer> and <size> arguments (16 bytes per line).
151 * The <string> argument is displayed before the buffer content.
152 * The line format is an address folowed by 16 (hexa) bytes.
153 **********************************************************************************
154 * @ string   : buffer name or identifier.
155 * @ buffer   : local pointer on bytes array.
156 * @ size     : number of bytes bytes to display.
157 *********************************************************************************/
158void putb( char     * string,
159           uint8_t  * buffer,
160           uint32_t   size );
161
162
163
164#endif  // _PRINTK_H
165
166// Local Variables:
167// tab-width: 4
168// c-basic-offset: 4
169// c-file-offsets:((innamespace . 0)(inline-open . 0))
170// indent-tabs-mode: nil
171// End:
172// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
173
Note: See TracBrowser for help on using the repository browser.