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

Last change on this file since 623 was 623, checked in by alain, 3 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
RevLine 
[1]1/*
2 * printk.h - Kernel Log & debug messages API definition.
[372]3 *
[437]4 * authors  Alain Greiner (2016,2017,2018)
[1]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
[623]26// to display messages on the kernel terminal TXT0, using a busy waiting policy.
27// It calls synchronously the TXT0 driver, without descheduling.
[1]28///////////////////////////////////////////////////////////////////////////////////
29
30#ifndef _PRINTK_H
31#define _PRINTK_H
32
[457]33#include <hal_kernel_types.h>
[5]34#include <stdarg.h>
[1]35
[623]36#include <hal_special.h> 
[5]37
38/**********************************************************************************
[372]39 * This function build a formatted string.
[23]40 * The supported formats are defined below :
[623]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)
[23]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/**********************************************************************************
[372]61 * This function displays a formatted string on the kernel terminal TXT0,
[296]62 * after taking the TXT0 lock.
[564]63 * It uses a busy waiting policy, calling directly the relevant TXT driver,
[5]64 **********************************************************************************
[372]65 * @ format     : formatted string.
[5]66 *********************************************************************************/
[103]67void printk( char* format, ... );
[1]68
[5]69/**********************************************************************************
[372]70 * This function displays a formatted string on the kernel terminal TXT0,
[296]71 * without taking the TXT0 lock.
[564]72 * It uses a busy waiting policy, calling directly the relevant TXT driver,
[296]73 **********************************************************************************
[372]74 * @ format     : formatted string.
[296]75 *********************************************************************************/
76void nolock_printk( char* format, ... );
77
[491]78
[296]79/**********************************************************************************
[564]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).
[491]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 *********************************************************************************/
[583]93void panic( const char * function_name,
[564]94            uint32_t     line,
95            cycle_t      cycle,
96            const char * format,
97            ... ) __attribute__((__noreturn__));
[491]98
99/**********************************************************************************
100 * This macro displays a formated message on kernel TXT0 terminal,
[408]101 * and forces the calling core in sleeping mode if a Boolean condition is false.
[491]102 * Actually used to debug the kernel.
103 *
[583]104 * Extra information printed by assert:
105 * - Current thread, process, and core
106 * - Function name / line number in file / cycle
[5]107 **********************************************************************************
108 * @ condition     : condition that must be true.
[372]109 * @ format        : formatted string
[5]110 *********************************************************************************/
[564]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    {                                                                             \
[583]117        panic( __FUNCTION__,                                                      \
118               __line_at_expansion,                                               \
119               __assert_cycle,                                                    \
[564]120               ( format ), ##__VA_ARGS__ );                                       \
121    }                                                                             \
[491]122}
[5]123
[408]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
[623]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 );
[408]161
[623]162
163
[1]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.