From e14535feaaaed76d598a0873e9d7ca5e8d8b658a Mon Sep 17 00:00:00 2001 From: fslongjin Date: Tue, 26 Jul 2022 17:42:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3printk=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E5=87=BD=E6=95=B0=E6=B2=A1=E6=9C=89=E5=8A=A0?= =?UTF-8?q?static=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/common/printk.c | 78 ++++++++++++++++++++++++++++++-------- kernel/common/printk.h | 49 ++---------------------- kernel/common/stdio.h | 6 +++ kernel/ktest/ktest_utils.h | 24 ++++++------ 4 files changed, 84 insertions(+), 73 deletions(-) diff --git a/kernel/common/printk.c b/kernel/common/printk.c index fd493463..4b9afcc2 100644 --- a/kernel/common/printk.c +++ b/kernel/common/printk.c @@ -10,14 +10,65 @@ #include #include #include "math.h" -//#include "linkage.h" struct printk_screen_info pos; extern ul VBE_FB_phys_addr; // 由bootloader传来的帧缓存区的物理地址 static spinlock_t printk_lock; static bool sw_show_scroll_animation = false; // 显示换行动画的开关 -int calculate_max_charNum(int len, int size) +/** + * @brief Set the printk pos object + * + * @param x 列坐标 + * @param y 行坐标 + */ +static int set_printk_pos(const int x, const int y); + +/** + * @brief 在屏幕上指定位置打印字符 + * + * @param fb 帧缓存线性地址 + * @param Xsize 行分辨率 + * @param x 左上角列像素点位置 + * @param y 左上角行像素点位置 + * @param FRcolor 字体颜色 + * @param BKcolor 背景颜色 + * @param font 字符的bitmap + */ +static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, unsigned int BKcolor, unsigned char font); + +static uint *get_pos_VBE_FB_addr(); + +/** + * @brief 清屏 + * + */ +static int cls(); + +/** + * @brief 滚动窗口(尚不支持向下滚动) + * + * @param direction 方向,向上滑动为true,否则为false + * @param pixels 要滑动的像素数量 + * @param animation 是否包含滑动动画 + */ +static int scroll(bool direction, int pixels, bool animation); + +/** + * @brief 将数字按照指定的要求转换成对应的字符串(2~36进制) + * + * @param str 要返回的字符串 + * @param num 要打印的数值 + * @param base 基数 + * @param field_width 区域宽度 + * @param precision 精度 + * @param flags 标志位 + */ +static char *write_num(char *str,ul num, int base, int field_width, int precision, int flags); + +static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags); + +static int calculate_max_charNum(int len, int size) { /** * @brief 计算屏幕上能有多少行 @@ -85,7 +136,7 @@ int printk_init(const int char_size_x, const int char_size_y) return 0; } -int set_printk_pos(const int x, const int y) +static int set_printk_pos(const int x, const int y) { // 指定的坐标不在屏幕范围内 if (!((x >= 0 && x <= pos.max_x) && (y >= 0 && y <= pos.max_y))) @@ -94,7 +145,7 @@ int set_printk_pos(const int x, const int y) pos.y = y; return 0; } -int skip_and_atoi(const char **s) +static int skip_and_atoi(const char **s) { /** * @brief 获取连续的一段字符对应整数的值 @@ -109,7 +160,7 @@ int skip_and_atoi(const char **s) return ans; } -void auto_newline() +static void auto_newline() { /** * @brief 超过每行最大字符数,自动换行 @@ -138,7 +189,7 @@ void auto_newline() } } -static int vsprintf(char *buf, const char *fmt, va_list args) +int vsprintf(char *buf, const char *fmt, va_list args) { /** * 将字符串按照fmt和args中的内容进行格式化,然后保存到buf中 @@ -535,7 +586,6 @@ static char *write_num(char *str, ul num, int base, int field_width, int precisi return str; } - static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags) { /** @@ -573,9 +623,9 @@ static char *write_float_point_num(char *str, double num, int field_width, int p if (sign) --field_width; - int js_num_z = 0, js_num_d = 0; // 临时数字字符串tmp_num_z tmp_num_d的长度 - uint64_t num_z = (uint64_t)(num); // 获取整数部分 - uint64_t num_decimal = (uint64_t)(round(1.0*(num - num_z) * pow(10, precision))); // 获取小数部分 + int js_num_z = 0, js_num_d = 0; // 临时数字字符串tmp_num_z tmp_num_d的长度 + uint64_t num_z = (uint64_t)(num); // 获取整数部分 + uint64_t num_decimal = (uint64_t)(round(1.0 * (num - num_z) * pow(10, precision))); // 获取小数部分 if (num == 0 || num_z == 0) tmp_num_z[js_num_z++] = '0'; @@ -776,9 +826,7 @@ int do_scroll(bool direction, int pixels) * @param pixels 要滑动的像素数量 * @param animation 是否包含滑动动画 */ - -// @todo: 修复用户态触发键盘中断时产生#UD错误 -int scroll(bool direction, int pixels, bool animation) +static int scroll(bool direction, int pixels, bool animation) { // 暂时不支持反方向滚动 if (direction == false) @@ -851,7 +899,7 @@ int scroll(bool direction, int pixels, bool animation) * @brief 清屏 * */ -int cls() +static int cls() { memset(pos.FB_address, BLACK, pos.FB_length * sizeof(unsigned int)); pos.x = 0; @@ -876,7 +924,7 @@ void set_pos_VBE_FB_addr(uint *virt_addr) pos.FB_address = (uint *)virt_addr; } -uint *get_pos_VBE_FB_addr() +static uint *get_pos_VBE_FB_addr() { return pos.FB_address; } diff --git a/kernel/common/printk.h b/kernel/common/printk.h index 6df01d42..091d304c 100644 --- a/kernel/common/printk.h +++ b/kernel/common/printk.h @@ -61,13 +61,7 @@ extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大 * @param char_size_y 字符的行坐标 */ int printk_init(const int char_size_x, const int char_size_y); -/** - * @brief Set the printk pos object - * - * @param x 列坐标 - * @param y 行坐标 - */ -int set_printk_pos(const int x, const int y); + /** * @brief 将字符串按照fmt和args中的内容进行格式化,然后保存到buf中 * @@ -76,34 +70,10 @@ int set_printk_pos(const int x, const int y); * @param args 内容 * @return 最终字符串的长度 */ -static int vsprintf(char *buf, const char *fmt, va_list args); +int vsprintf(char *buf, const char *fmt, va_list args); -/** - * @brief 将数字按照指定的要求转换成对应的字符串(2~36进制) - * - * @param str 要返回的字符串 - * @param num 要打印的数值 - * @param base 基数 - * @param field_width 区域宽度 - * @param precision 精度 - * @param flags 标志位 - */ -static char *write_num(char *str,ul num, int base, int field_width, int precision, int flags); -static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags); -/** - * @brief 在屏幕上指定位置打印字符 - * - * @param fb 帧缓存线性地址 - * @param Xsize 行分辨率 - * @param x 左上角列像素点位置 - * @param y 左上角行像素点位置 - * @param FRcolor 字体颜色 - * @param BKcolor 背景颜色 - * @param font 字符的bitmap - */ -static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, unsigned int BKcolor, unsigned char font); /** * @brief 格式化打印字符串 @@ -117,20 +87,7 @@ static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, uns int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...); -/** - * @brief 滚动窗口(尚不支持向下滚动) - * - * @param direction 方向,向上滑动为true,否则为false - * @param pixels 要滑动的像素数量 - * @param animation 是否包含滑动动画 - */ -int scroll(bool direction, int pixels, bool animation); -/** - * @brief 清屏 - * - */ -int cls(); /** @@ -145,7 +102,7 @@ ul get_VBE_FB_length(); */ void set_pos_VBE_FB_addr(uint* virt_addr); -uint* get_pos_VBE_FB_addr(); + /** * @brief 使能滚动动画 diff --git a/kernel/common/stdio.h b/kernel/common/stdio.h index c232081b..abe28f65 100644 --- a/kernel/common/stdio.h +++ b/kernel/common/stdio.h @@ -1,7 +1,13 @@ #pragma once +#include +#include #define SEEK_SET 0 /* Seek relative to start-of-file */ #define SEEK_CUR 1 /* Seek relative to current position */ #define SEEK_END 2 /* Seek relative to end-of-file */ #define SEEK_MAX 3 + +extern int vsprintf(char *buf, const char *fmt, va_list args); + +extern int sprintk(char *buf, const char *fmt, ...); \ No newline at end of file diff --git a/kernel/ktest/ktest_utils.h b/kernel/ktest/ktest_utils.h index b186b6f3..b01f4d43 100644 --- a/kernel/ktest/ktest_utils.h +++ b/kernel/ktest/ktest_utils.h @@ -3,25 +3,25 @@ #include #include -#define assert(condition) ({ \ - int __condition = !!(condition); \ - if (unlikely(!(__condition))) \ - { \ +#define assert(condition) ({ \ + int __condition = !!(condition); \ + if (unlikely(!(__condition))) \ + { \ printk("[ kTEST FAILED ] Ktest Assertion Failed, file:%s, Line:%d\n", __FILE__, __LINE__); \ - } \ - likely(__condition); \ + } \ + likely(__condition); \ }) -#define kTEST(...) \ - do \ - { \ +#define kTEST(...) \ + do \ + { \ printk("[ kTEST ] file:%s, Line:%d\t", __FILE__, __LINE__); \ - printk(__VA_ARGS__); \ - printk("\n"); \ + printk(__VA_ARGS__); \ + printk("\n"); \ } while (0); /** * @brief 测试用例函数表 - * + * */ typedef long (*ktest_case_table)(uint64_t arg0, uint64_t arg1); \ No newline at end of file