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

Last change on this file since 641 was 625, checked in by alain, 6 years ago

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

File size: 8.9 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 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 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 32 bits signed value in decimal on TXT0 terminal.
142 * This function is actually used to debug the assembly level kernel functions.
143 **********************************************************************************
144 * @ val   : 32 bits signed value.
145 *********************************************************************************/
146void putd( int32_t val );
147
148/**********************************************************************************
149 * This function displays a 64 bits value in hexadecimal on TXT0 terminal.
150 * This function is actually used to debug the assembly level kernel functions.
151 **********************************************************************************
152 * @ val   : 64 bits unsigned value.
153 *********************************************************************************/
154void putl( uint64_t val );
155
156/**********************************************************************************
157 * This debug function displays on the TXT0 terminal the content of an
158 * array of bytes defined by <buffer> and <size> arguments (16 bytes per line).
159 * The <string> argument is displayed before the buffer content.
160 * The line format is an address folowed by 16 (hexa) bytes.
161 **********************************************************************************
162 * @ string   : buffer name or identifier.
163 * @ buffer   : local pointer on bytes array.
164 * @ size     : number of bytes bytes to display.
165 *********************************************************************************/
166void putb( char     * string,
167           uint8_t  * buffer,
168           uint32_t   size );
169
170
171
172#endif  // _PRINTK_H
173
174// Local Variables:
175// tab-width: 4
176// c-basic-offset: 4
177// c-file-offsets:((innamespace . 0)(inline-open . 0))
178// indent-tabs-mode: nil
179// End:
180// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
181
Note: See TracBrowser for help on using the repository browser.