-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68ccd31
commit ec64227
Showing
22 changed files
with
589 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ my_simple_kernel | |
*.o | ||
|
||
#软盘文件 | ||
*.img | ||
*.img | ||
|
||
cmake-build-debug/* | ||
|
||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 文件名:question.list | ||
* 作者: 李程鹏 | ||
* 描述: 遇到的问题列表, 我会一定时间更新标注对于问题的解决状态, 也欢迎大家提供建议, 谢谢! | ||
*/ | ||
|
||
1. 对于memset这个函数, 有问题吧, 它的dest和src大小不匹配怎么办, 我还是写成memset_int,memset_short和memset_char好了,具体的只用一个函数实现不知道怎么解决. (未解决) | ||
|
||
2. 我得实现一个方便一点的打印接口函数,用于调试,不然就用我写的那几个基本的输出函数也太太太麻烦了吧!!!( 未解决) | ||
|
||
3. strcpy中,当src字符串比目标字符窜长的时候怎么处理呢? 为目标字符窜寻找更大的空间, 还是直接把src切成和目标字符窜一样长,还是假设调用者知道给的目标字符串的空间足够大? 暂时假设调用者知道吧!! 但如果不知道,那将很危险, 一不小心保存的栈就被破坏了, 还是干脆让用户麻烦一点, 添加一个目标字符串容量的参数, 来提醒使用者......(未解决) | ||
|
||
4. 呼......我已经感受到print()函数的实现难度了(实现中...). 2018年2月3日,已解决. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
*文件名: print.h. | ||
*作者: 李程鹏 on 18-2-3. | ||
*描述: 包含内核级打印函数的声明. | ||
*/ | ||
|
||
#ifndef OS_PRINT_H | ||
#define OS_PRINT_H | ||
|
||
#include "console.h" | ||
|
||
// 根据给出的字符串的格式和可变参数列表以及颜色,打印带颜色的字符串 | ||
void printk_color(real_color_t fore,real_color_t back,char* format,...); | ||
|
||
#endif //OS_PRINT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
*文件名: string.h | ||
* 作者: 李程鹏 | ||
* 描述: 这个文件包含对字符串操作的基本定义 | ||
*/ | ||
|
||
#ifndef INCLUDE_STRING_H | ||
#define INCLUDE_STRING_H | ||
|
||
#include "types.h" | ||
|
||
// 分别以32位,16位和8位的形式复制给定长度,给定值的数据到指定位置. | ||
void memset_uint32(uint32_t* dest,uint32_t value, int len ); | ||
void memset_uint16(uint16_t* dest,uint16_t value, int len ); | ||
void memset_uint8(uint8_t* dest,uint8_t value, int len ); | ||
|
||
// 分别以32位,16位和8位的形式复制给定长度,给定位置的数据到指定位置. | ||
void memcpy_uint32(uint32_t* dest,uint32_t* src,int len); | ||
void memcpy_uint16(uint16_t* dest,uint16_t* src,int len); | ||
void memcpy_uint8(uint8_t* dest,uint8_t* src,int len); | ||
|
||
/*以下为基本的字符串操作函数*/ | ||
|
||
// 获取字符串长度 | ||
int strlen(char* str); | ||
|
||
/* | ||
*比较字符串大小 | ||
*return 0: str1==str2; 1:str1>str2; -1:str1<str2 | ||
*/ | ||
int strcmp(char* str1,char* str2); | ||
|
||
// 复制src字符串的内容到dest字符串 | ||
void strcpy(char* dest,char* src); | ||
|
||
// 把src字符串的内容连接到dest字符串后面 | ||
void strcat(char* dest,char* src); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
*文件名: vargs.h. | ||
*作者: 李程鹏 on 18-2-3. | ||
*描述: 该文件包含可变长参数获取操作的一些定义 | ||
*/ | ||
|
||
#ifndef OS_VARGS_H | ||
#define OS_VARGS_H | ||
|
||
typedef __builtin_va_list va_list; | ||
|
||
#define va_start(list,start) (__builtin_va_start(list,start)) //获取可变长参数列表的起始地址 | ||
#define va_arg(list,type) (__builtin_va_arg(list,type)) //根据当前可变长参数列表的位置和类型,获取该参数 | ||
#define va_end(list) (list=(va_list)0) // 将当前可变长参数地址清零 | ||
|
||
#endif //OS_VARGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
*文件名: print.c. | ||
*作者: 李程鹏 on 18-2-3. | ||
*描述: | ||
*/ | ||
|
||
#include "print.h" | ||
#include "vargs.h" | ||
#include "console.h" | ||
#include "types.h" | ||
|
||
// 判断一个字符是否是数字范围 | ||
static int isDigit(char c){ | ||
if(c>='0'&&c<='9') return 1; | ||
return 0; | ||
} | ||
|
||
// 将一个字符串转换成一个整数输出, 这里默认字符串代表的是一个自然数 | ||
static int to_number(char* str){ | ||
int result=0,i=0; | ||
for (;str[i]!=0;i++) | ||
result=result*10+(str[i]-'0'); | ||
return result; | ||
} | ||
|
||
// 打印指定长度的空格 | ||
static void print_blank(int len){ | ||
int i=0; | ||
for(;i<len;i++) | ||
console_putc_color(' ',rc_white,rc_black); | ||
} | ||
|
||
// 根据给出的字符串的格式和可变参数列表以及颜色,打印带颜色的字符串 | ||
void printk_color(real_color_t fore,real_color_t back,char* format,...) | ||
{ | ||
// 初始化可变长参数的文字 | ||
va_list list; | ||
va_start(list,format); | ||
|
||
// 记录当前的输出位置 | ||
int i=0; | ||
|
||
// 临时存放字符串 | ||
char temp[10];int tempPos=0; | ||
|
||
for(;format[i]!=0;i++) | ||
{ | ||
// 检测字符是否为井号, 如果不是,则说明是一般字符,直接打印出来就好了,要输出一个井号,则需要输入2个井号 | ||
if(format[i]!='#'){ | ||
console_putc_color(format[i],fore,back); | ||
continue; | ||
} | ||
|
||
i++; | ||
switch (format[i]){ | ||
case 0: //不小心到达字符串末尾了 | ||
console_putc_color(format[i-1],fore,back); | ||
goto charEnd; | ||
case '#': //对的,如果要输出#号,你需要打2个 | ||
console_putc_color(format[i-1],fore,back); | ||
break; | ||
case 'd': //整数 | ||
console_write_dec_sign(va_arg(list,int32_t),fore,back); | ||
break; | ||
case 'x': //十六进制整数 | ||
console_write_hex(va_arg(list,uint32_t),fore,back); | ||
break; | ||
case 'u': //无符号整数 | ||
console_write_dec(va_arg(list,uint32_t),fore,back); | ||
break; | ||
case 'c': //字符 | ||
console_putc_color((uint8_t)(va_arg(list,uint32_t)),fore,back); | ||
break; | ||
case 's': //字符串 | ||
console_write_color(va_arg(list,char*),fore,back); | ||
break; | ||
case 'l': | ||
case 'f': //浮点数 | ||
// 'f'之后紧跟数字表示要保留的小数点个数 | ||
i++; | ||
if(isDigit(format[i])){ | ||
temp[tempPos]=format[i]; | ||
while (isDigit(format[++i])) | ||
temp[++tempPos]=format[i]; | ||
temp[++tempPos]=0; | ||
// console_write_dec_sign(to_number(temp),fore,back); | ||
console_write_float(va_arg(list,double),to_number(temp),fore,back); | ||
tempPos=0; | ||
}else | ||
console_write_float(va_arg(list,double),6,fore,back); | ||
i--; | ||
break; | ||
default: | ||
// '#'之后紧跟数字表示要输出多少个空格 | ||
if(isDigit(format[i])){ | ||
temp[tempPos]=format[i]; | ||
while (isDigit(format[++i])) | ||
temp[++tempPos]=format[i]; | ||
temp[++tempPos]=0; | ||
print_blank(to_number(temp)); //这里temp可不能用指针啊,不小心就把输入的format给改变了. | ||
tempPos=0;i--; | ||
} | ||
// 这么多规则都不匹配之后,只能说明用户的输入有问题,或者还有什么我没有想到的地方(这里纯属设计问题了哈) | ||
else{ | ||
if(format[i]==' '||format[i]=='\t'||format[i]=='\n'||format[i]=='\f'){ | ||
console_putc_color(format[i-1],fore,back); | ||
console_putc_color(format[i],fore,back); | ||
} | ||
else{ | ||
console_write_color("No matching rules,please check your input!",rc_red,rc_black); | ||
goto charEnd; //切切, 老师叫不用就不用啊. | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
charEnd:va_end(list); | ||
} |
Oops, something went wrong.