remove asm print in kernel

This commit is contained in:
catfood 2023-11-22 20:58:04 +08:00
parent d41b8fa451
commit 175b9e7da3
28 changed files with 370 additions and 370 deletions

View File

@ -13,7 +13,7 @@
#ifndef _ORANGES_CONSOLE_H_
#define _ORANGES_CONSOLE_H_
#include "const.h"
/* CONSOLE */
typedef struct s_console
@ -30,12 +30,18 @@ typedef struct s_console
#define SCR_UP 1 /* scroll upward */
#define SCR_DN -1 /* scroll downward */
#define SCR_SIZE (80 * 25)
#define SCR_WIDTH 80
#define DEFAULT_CHAR_COLOR (MAKE_COLOR(BLACK, WHITE))
#define GRAY_CHAR (MAKE_COLOR(BLACK, BLACK) | BRIGHT)
#define RED_CHAR (MAKE_COLOR(BLUE, RED) | BRIGHT)
#define SCR_WIDTH 80
#define SCR_HEIGHT 25
#define SCR_SIZE (SCR_HEIGHT * SCR_WIDTH)
#define SCR_BUFSIZE (2 * SCR_SIZE)
#define SCR_MAXLINE (SCR_BUFSIZE / SCR_WIDTH)
#define FLASH_CHAR 0x8000
#define DEFAULT_CHAR_COLOR ((MAKE_COLOR(BLACK, WHITE | BRIGHT)) << 8)
#define GRAY_CHAR (MAKE_COLOR(BLACK, BLACK) | BRIGHT)
#define RED_CHAR (MAKE_COLOR(BLUE, RED) | BRIGHT)
#define WHITE_CHAR (MAKE_COLOR(BLACK, WHITE | BRIGHT))
#define MAKE_CELL(clr, ch) (clr | ch)
#define BLANK MAKE_CELL(DEFAULT_CHAR_COLOR, ' ')
#endif /* _ORANGES_CONSOLE_H_ */

View File

@ -165,6 +165,7 @@
//added by mingxuan 2019-5-19
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
#define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data Register */
#define UNDERLINE_REG 0x14 /* reg index of underline */
#define START_ADDR_H 0xC /* reg index of video mem start addr (MSB) */
#define START_ADDR_L 0xD /* reg index of video mem start addr (LSB) */
#define CURSOR_H 0xE /* reg index of cursor position (MSB) */

View File

@ -12,7 +12,6 @@ extern int kernel_initial;
extern int ticks;
extern int disp_pos;
extern u8 gdt_ptr[6]; // 0~15:Limit 16~47:Base
extern DESCRIPTOR gdt[GDT_SIZE];
extern u8 idt_ptr[6]; // 0~15:Limit 16~47:Base

View File

@ -6,10 +6,12 @@
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* klib.asm */
void disp_str(char* info);
void disp_int(int input);
void disp_color_str(char* info, int color);
void write_char(char ch); //added by mingxuan 2019-5-19
void vga_set_disppos(int new_pos);
int vga_get_disppos();
void vga_write_char(const char ch, u8 color);
void vga_write_str(const char * str);
void vga_write_str_color(const char * str, u8 color);
//added by zcr
void disable_irq(int irq);
@ -22,7 +24,6 @@ void init_prot();
u32 seg2phys(u16 seg);
/* klib.c */
void delay(int time);
/* kernel.asm */
u32 read_cr2(); //add by visual 2016.5.9

View File

@ -13,7 +13,7 @@
#ifndef _ORANGES_TTY_H_
#define _ORANGES_TTY_H_
#include "type.h"
#define TTY_IN_BYTES 256 /* tty input queue size */
#define TTY_OUT_BUF_LEN 2 /* tty output buffer size */

12
include/uart.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef UART_H
#define UART_H
#define PORT 0x3f8 // COM1
#define SERIAL_BUF_SIZE 256
int init_serial();
char read_serial();
void write_serial(char a);
#endif

View File

@ -30,8 +30,7 @@ KERN_SRCFILES :=kernel/kernel.asm \
kernel/i8259.c \
kernel/testfunc.c \
kernel/protect.c \
lib/klib.c \
lib/kliba.asm \
kernel/uart.c \
KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))

View File

@ -48,7 +48,7 @@ void init_screen(TTY* tty)
tty->console->current_line = 0;
if(nr_tty==0){
tty->console->cursor = disp_pos / 2;
tty->console->cursor = vga_get_disppos();
}
const char prompt[] = "[TTY #?]\n";
@ -87,15 +87,15 @@ void out_char(CONSOLE* con, char ch)
con->cursor--;
//*(pch - 2) = ' ';
//*(pch - 1) = DEFAULT_CHAR_COLOR;
disp_pos = con->cursor*2;
write_char(' ');
vga_set_disppos(con->cursor);
vga_write_char(' ', WHITE_CHAR);
}
break;
default:
//*pch++ = ch;
//*pch++ = DEFAULT_CHAR_COLOR;
disp_pos = con->cursor*2;
write_char(ch);
vga_set_disppos(con->cursor);
vga_write_char(ch, WHITE_CHAR);
con->cursor++;
break;
@ -144,7 +144,7 @@ static void clear_screen(int pos, int len)
u8 * pch = (u8*)K_PHY2LIN(V_MEM_BASE + pos * 2);
while (--len >= 0) {
*pch++ = ' ';
*pch++ = DEFAULT_CHAR_COLOR;
*pch++ = (u8)DEFAULT_CHAR_COLOR;
}
}

View File

@ -35,7 +35,7 @@ u32 sys_exec(char *path)
if( 0==path )
{
disp_color_str("exec: path ERROR!",0x74);
vga_write_str_color("exec: path ERROR!",0x74);
return -1;
}
@ -86,7 +86,7 @@ u32 sys_exec(char *path)
if( err_temp!=0 )
{
disp_color_str("kernel_main Error:lin_mapping_phy",0x74);
vga_write_str_color("kernel_main Error:lin_mapping_phy",0x74);
return -1;
}
}
@ -98,9 +98,9 @@ u32 sys_exec(char *path)
if (Echo_Phdr != NULL)
sys_free(Echo_Phdr);
//disp_color_str("\n[exec success:",0x72);//灰底绿字
//disp_color_str(path,0x72);//灰底绿字
//disp_color_str("]",0x72);//灰底绿字
//vga_write_str_color("\n[exec success:",0x72);//灰底绿字
//vga_write_str_color(path,0x72);//灰底绿字
//vga_write_str_color("]",0x72);//灰底绿字
return 0;
}
@ -157,7 +157,7 @@ static u32 exec_load(u32 fd,const Elf32_Ehdr* Echo_Ehdr,const Elf32_Phdr Echo_Ph
if( 0==Echo_Ehdr->e_phnum )
{
disp_color_str("exec_load: elf ERROR!",0x74);
vga_write_str_color("exec_load: elf ERROR!",0x74);
return -1;
}
@ -183,7 +183,7 @@ static u32 exec_load(u32 fd,const Elf32_Ehdr* Echo_Ehdr,const Elf32_Phdr Echo_Ph
}
else
{
disp_color_str("exec_load: unKnown elf'program!",0x74);
vga_write_str_color("exec_load: unKnown elf'program!",0x74);
return -1;
}
}

View File

@ -179,7 +179,7 @@ STATE ReadFile(int fd,void *buf, int length)
return ACCESSDENIED;
}
disp_str("read:");
kprintf("read:");
if(pfile->off>=pfile->size)
{
return 0;
@ -351,8 +351,8 @@ STATE OpenFile(const char *filename,int mode)
GetNameFromPath(fullpath,name);
state=PathToCluster(parent,&parentCluster);
disp_str("\nstate=");
disp_int(state);
kprintf("\nstate=");
kprintf("%d", state);
if(state!=OK)
{
return -1;
@ -364,7 +364,7 @@ STATE OpenFile(const char *filename,int mode)
{
if(state == NAMEEXIST) //文件存在使用O_CREAT是多余的继续执行OpenFile即可
{
disp_str("file exists, O_CREAT is no use!");
kprintf("file exists, O_CREAT is no use!");
}
else //文件不存在需要使用O_CREAT先创建文件再执行OpenFile
{
@ -376,7 +376,7 @@ STATE OpenFile(const char *filename,int mode)
{
if(state != NAMEEXIST) //文件不存在需要使用O_CREAT用户没有使用则报错并返回-1表示路径有误
{
disp_str("no file, use O_CREAT!");
kprintf("no file, use O_CREAT!");
return -1;
}
else{} //文件存在使用O_CREAT是多余的继续执行OpenFile即可
@ -384,11 +384,11 @@ STATE OpenFile(const char *filename,int mode)
//~mingxuan 2019-5-19
state=ReadRecord(parentCluster,name,&record,NULL,NULL);
disp_str("state=");
disp_int(state);
kprintf("state=");
kprintf("%d", state);
if(state!=OK)
{
disp_str("ReadRecord Fail!");
kprintf("ReadRecord Fail!");
return -1;
}
@ -403,9 +403,9 @@ STATE OpenFile(const char *filename,int mode)
if ((fd < 0) || (fd >= NR_FILES)) {
// panic("filp[] is full (PID:%d)", proc2pid(p_proc_current));
disp_str("filp[] is full (PID:");
disp_int(proc2pid(p_proc_current));
disp_str(")\n");
kprintf("filp[] is full (PID:");
kprintf("%d", proc2pid(p_proc_current));
kprintf(")\n");
return -1;
}
@ -414,9 +414,9 @@ STATE OpenFile(const char *filename,int mode)
if ((f_desc_table[i].flag == 0))
break;
if (i >= NR_FILE_DESC) {
disp_str("f_desc_table[] is full (PID:");
disp_int(proc2pid(p_proc_current));
disp_str(")\n");
kprintf("f_desc_table[] is full (PID:");
kprintf("%d", proc2pid(p_proc_current));
kprintf(")\n");
return -1;
}
@ -428,9 +428,9 @@ STATE OpenFile(const char *filename,int mode)
if (f_desc_table_fat[i].flag == 0)
break;
if (i >= NR_FILE_DESC) {
disp_str("f_desc_table[] is full (PID:");
disp_int(proc2pid(p_proc_current));
disp_str(")\n");
kprintf("f_desc_table[] is full (PID:");
kprintf("%d", proc2pid(p_proc_current));
kprintf(")\n");
}
//以下是给File结构体赋值
@ -442,9 +442,9 @@ STATE OpenFile(const char *filename,int mode)
f_desc_table_fat[i].off=0;
f_desc_table_fat[i].size=record.filelength;
f_desc_table_fat[i].flag=mode;
// disp_str("flag:");
// kprintf("flag:");
// deint(f_desc_table_fat[i].flag);
// disp_str("index:");
// kprintf("index:");
// deint(i);
p_proc_current->task.filp[fd] ->fd_node.fd_file = &f_desc_table_fat[i];
@ -552,7 +552,7 @@ STATE IsFile(PCHAR path,PUINT tag)
void init_fs_fat()
{
disp_str("Initializing fat32 file system... \n");
kprintf("Initializing fat32 file system... \n");
buf = (u8*)K_PHY2LIN(sys_kmalloc(FSBUF_SIZE));
@ -611,9 +611,9 @@ static void mkfs_fat() {
driver_msg.PROC_NR = proc2pid(p_proc_current);
hd_ioctl(&driver_msg);
disp_str("dev size: ");
disp_int(geo.size);
disp_str(" sectors\n");
kprintf("dev size: ");
kprintf("%d", geo.size);
kprintf(" sectors\n");
TotalSectors = geo.size;
@ -870,7 +870,7 @@ int sys_ListDir(void *uesp) {
// DirCheckup(array);
// }else {
// DisErrorInfo(state);
// disp_str("\n");
// kprintf("\n");
// }
// DestroyDArray(array);
return 0;
@ -880,31 +880,31 @@ void DisErrorInfo(STATE state)
{
if(state==SYSERROR)
{
disp_str(" system error\n");
kprintf(" system error\n");
}
else if(state==VDISKERROR)
{
disp_str(" disk error\n");
kprintf(" disk error\n");
}
else if(state==INSUFFICIENTSPACE)
{
disp_str(" no much space\n");
kprintf(" no much space\n");
}
else if(state==WRONGPATH)
{
disp_str(" path error\n");
kprintf(" path error\n");
}
else if(state==NAMEEXIST)
{
disp_str(" name exists\n");
kprintf(" name exists\n");
}
else if(state==ACCESSDENIED)
{
disp_str(" deny access\n");
kprintf(" deny access\n");
}
else
{
disp_str(" unknown error\n");
kprintf(" unknown error\n");
}
}

View File

@ -28,7 +28,7 @@ int sys_fork()
p_child = alloc_PCB();
if( 0==p_child )
{
disp_color_str("PCB NULL,fork faild!",0x74);
vga_write_str_color("PCB NULL,fork faild!",0x74);
return -1;
}
else
@ -56,9 +56,9 @@ int sys_fork()
/****************用户进程数+1****************************/
u_proc_sum += 1;
disp_color_str("[fork success:",0x72);
disp_color_str(p_proc_current->task.p_name,0x72);
disp_color_str("]",0x72);
vga_write_str_color("[fork success:",0x72);
vga_write_str_color(p_proc_current->task.p_name,0x72);
vga_write_str_color("]",0x72);
//anything child need is prepared now, set its state to ready. added by xw, 17/12/11
p_child->task.stat = READY;

View File

@ -24,7 +24,6 @@
int kernel_initial;
int ticks;
int disp_pos;
u8 gdt_ptr[6];
DESCRIPTOR gdt[GDT_SIZE];
u8 idt_ptr[6];

View File

@ -15,11 +15,9 @@ extern exception_handler
extern spurious_irq
extern clock_handler
extern disp_str
extern delay
extern irq_table
extern page_fault_handler
extern divide_error_handler ;added by xw, 18/12/22
extern disp_int
extern schedule
extern switch_pde
@ -28,7 +26,6 @@ extern gdt_ptr
extern idt_ptr
extern p_proc_current
extern tss
extern disp_pos
extern k_reenter
extern sys_call_table
extern cr3_ready ;add by visual 2016.4.5
@ -141,7 +138,6 @@ _start:
;mov esp, StackTop ; 堆栈在 bss 段中
mov esp, KernelStackTop ; 堆栈在 bss 段中
mov dword [disp_pos], 0
sgdt [gdt_ptr] ; cstart() 中将会用到 gdt_ptr
call cstart ; 在此函数中改变了gdt_ptr让它指向新的GDT

View File

@ -32,13 +32,13 @@ int kernel_main()
{
int error;
disp_pos = 0;
vga_set_disppos(0);
for (int i = 0; i < 25; i++) {
for (int j = 0; j < 80; j++) {
kprintf(" ");
}
}
disp_pos = 0;
vga_set_disppos(0);
kprintf("-----Kernel Initialization Begins-----\n");
kernel_initial = 1; //kernel is in initial state. added by xw, 18/5/31
@ -199,7 +199,7 @@ static int initialize_processes()
/***************初始化PID进程页表*****************************/
if( 0 != init_page_pte(pid) )
{
disp_color_str("kernel_main Error:init_page_pte",0x74);
vga_write_str_color("kernel_main Error:init_page_pte",0x74);
return -1;
}
// pde_addr_phy_temp = get_pde_phy_addr(pid);//获取该进程页目录物理地址 //delete by visual 2016.5.19
@ -214,7 +214,7 @@ static int initialize_processes()
//addr_phy_temp = (u32)do_kmalloc_4k();//为栈申请一个物理页,Task的栈是在内核里面 //delete by visual 2016.5.19
//if( addr_phy_temp<0 || (addr_phy_temp&0x3FF)!=0 )
//{
// disp_color_str("kernel_main Error:addr_phy_temp",0x74);
// vga_write_str_color("kernel_main Error:addr_phy_temp",0x74);
// return -1;
//}
err_temp = lin_mapping_phy( AddrLin,//线性地址 //add by visual 2016.5.9
@ -224,7 +224,7 @@ static int initialize_processes()
PG_P | PG_USU | PG_RWW);//页表的属性位
if( err_temp!=0 )
{
disp_color_str("kernel_main Error:lin_mapping_phy",0x74);
vga_write_str_color("kernel_main Error:lin_mapping_phy",0x74);
return -1;
}
@ -355,7 +355,7 @@ static int initialize_processes()
/***************初始化PID进程页表*****************************/
if( 0 != init_page_pte(pid) )
{
disp_color_str("kernel_main Error:init_page_pte",0x74);
vga_write_str_color("kernel_main Error:init_page_pte",0x74);
return -1;
}
//pde_addr_phy_temp = get_pde_phy_addr(pid);//获取该进程页目录物理地址 //edit by visual 2016.5.19
@ -370,7 +370,7 @@ static int initialize_processes()
//addr_phy_temp = (u32)do_kmalloc_4k();//为栈申请一个物理页,Task的栈是在内核里面 //delete by visual 2016.5.19
//if( addr_phy_temp<0 || (addr_phy_temp&0x3FF)!=0 )
//{
// disp_color_str("kernel_main Error:addr_phy_temp",0x74);
// vga_write_str_color("kernel_main Error:addr_phy_temp",0x74);
// return -1;
//}
err_temp = lin_mapping_phy( AddrLin,//线性地址
@ -380,7 +380,7 @@ static int initialize_processes()
PG_P | PG_USU | PG_RWW);//页表的属性位
if( err_temp!=0 )
{
disp_color_str("kernel_main Error:lin_mapping_phy",0x74);
vga_write_str_color("kernel_main Error:lin_mapping_phy",0x74);
return -1;
}

View File

@ -340,22 +340,22 @@ void memman_test()
p1 = (u32 *)do_malloc(4);
if(-1 != (u32)p1){ //打印p1当前空闲内存信息p1所指内存的内容
disp_str("START");
disp_int((u32)p1);
kprintf("START");
kprintf("%d", (u32)p1);
//disp_free();
*p1 = TEST;
disp_int(*p1);
disp_str("END");
kprintf("%d", *p1);
kprintf("END");
}
p2 = (u32 *)do_kmalloc(4);
if(-1 != (u32)p2){
disp_str("START");
disp_int((u32)p2);
kprintf("START");
kprintf("%d", (u32)p2);
//disp_free();
*p2 = TEST;
disp_int(*p2);
disp_str("END");
kprintf("%d", *p2);
kprintf("END");
}
do_free((u32)p1,4);
@ -363,42 +363,42 @@ void memman_test()
p3 = (u32 *)do_malloc_4k();
if(-1 != (u32)p3){
disp_str("START");
disp_int((u32)p3);
kprintf("START");
kprintf("%d", (u32)p3);
//disp_free();
*p3 = TEST;
disp_int(*p3);
kprintf("%d", *p3);
p = p3 + 2044;
*p = 0x22334455;
disp_int(*p);
kprintf("%d", *p);
p += 2048;
*p = 0x33445566;
disp_int(*p);
disp_str("END");
kprintf("%d", *p);
kprintf("END");
}
p4 = (u32 *)do_kmalloc_4k(4);
if(-1 != (u32)p4){
disp_str("START");
disp_int((u32)p4);
kprintf("START");
kprintf("%d", (u32)p4);
//disp_free();
*p4 = TEST;
disp_int(*p4);
kprintf("%d", *p4);
p = p4 + 2044;
*p = 0x22334455;
disp_int(*p);
kprintf("%d", *p);
p += 2048;
*p = 0x33445566;
disp_int(*p);
disp_str("END");
kprintf("%d", *p);
kprintf("END");
}
do_free_4k((u32)p3);
do_free_4k((u32)p4);
disp_str("START");
kprintf("START");
disp_free();
disp_str("END");
kprintf("END");
return;
}

View File

@ -10,6 +10,7 @@
#include "global.h"
#include "proto.h"
#include "memman.h"
#include "stdio.h"
// to determine if a page fault is reparable. added by xw, 18/6/11
u32 cr2_save;
@ -38,7 +39,7 @@ u32 init_page_pte(u32 pid)
if (pde_addr_phy_temp < 0 || (pde_addr_phy_temp & 0x3FF) != 0) // add by visual 2016.5.9
{
disp_color_str("init_page_pte Error:pde_addr_phy_temp", 0x74);
vga_write_str_color("init_page_pte Error:pde_addr_phy_temp", 0x74);
return -1;
}
@ -55,7 +56,7 @@ u32 init_page_pte(u32 pid)
PG_P | PG_USS | PG_RWW); //页表的属性位(系统权限) //edit by visual 2016.5.17
if (err_temp != 0)
{
disp_color_str("init_page_pte Error:lin_mapping_phy", 0x74);
vga_write_str_color("init_page_pte Error:lin_mapping_phy", 0x74);
return -1;
}
}
@ -81,18 +82,18 @@ void page_fault_handler(u32 vec_no, //异常编号此时应该是14
// if page fault happens in kernel, it's an error.
if (kernel_initial == 1)
{
disp_str("\n");
disp_color_str("Page Fault\n", 0x74);
disp_color_str("eip=", 0x74); //灰底红字
disp_int(eip);
disp_color_str("eflags=", 0x74);
disp_int(eflags);
disp_color_str("cs=", 0x74);
disp_int(cs);
disp_color_str("err_code=", 0x74);
disp_int(err_code);
disp_color_str("Cr2=", 0x74); //灰底红字
disp_int(cr2);
kprintf("\n");
vga_write_str_color("Page Fault\n", 0x74);
vga_write_str_color("eip=", 0x74); //灰底红字
kprintf("%d", eip);
vga_write_str_color("eflags=", 0x74);
kprintf("%d", eflags);
vga_write_str_color("cs=", 0x74);
kprintf("%d", cs);
vga_write_str_color("err_code=", 0x74);
kprintf("%d", err_code);
vga_write_str_color("Cr2=", 0x74); //灰底红字
kprintf("%d", cr2);
halt();
}
@ -106,26 +107,26 @@ void page_fault_handler(u32 vec_no, //异常编号此时应该是14
cr2_count++;
if (cr2_count == 5)
{
disp_str("\n");
disp_color_str("Page Fault\n", 0x74);
disp_color_str("eip=", 0x74); //灰底红字
disp_int(eip);
disp_color_str("eflags=", 0x74);
disp_int(eflags);
disp_color_str("cs=", 0x74);
disp_int(cs);
disp_color_str("err_code=", 0x74);
disp_int(err_code);
disp_color_str("Cr2=", 0x74); //灰底红字
disp_int(cr2);
disp_color_str("Cr3=", 0x74);
disp_int(p_proc_current->task.cr3);
kprintf("\n");
vga_write_str_color("Page Fault\n", 0x74);
vga_write_str_color("eip=", 0x74); //灰底红字
kprintf("%d", eip);
vga_write_str_color("eflags=", 0x74);
kprintf("%d", eflags);
vga_write_str_color("cs=", 0x74);
kprintf("%d", cs);
vga_write_str_color("err_code=", 0x74);
kprintf("%d", err_code);
vga_write_str_color("Cr2=", 0x74); //灰底红字
kprintf("%d", cr2);
vga_write_str_color("Cr3=", 0x74);
kprintf("%d", p_proc_current->task.cr3);
//获取页目录中填写的内容
disp_color_str("Pde=", 0x74);
disp_int(*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2)));
vga_write_str_color("Pde=", 0x74);
kprintf("%d", *((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2)));
//获取页表中填写的内容
disp_color_str("Pte=", 0x74);
disp_int(*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2)));
vga_write_str_color("Pte=", 0x74);
kprintf("%d", *((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2)));
halt();
}
}
@ -137,15 +138,15 @@ void page_fault_handler(u32 vec_no, //异常编号此时应该是14
if (0 == pte_exist(pde_addr_phy_temp, cr2))
{ //页表不存在
// disp_color_str("[Pde Fault!]",0x74); //灰底红字
// vga_write_str_color("[Pde Fault!]",0x74); //灰底红字
(*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2))) |= PG_P;
// disp_color_str("[Solved]",0x74);
// vga_write_str_color("[Solved]",0x74);
}
else
{ //只是缺少物理页
// disp_color_str("[Pte Fault!]",0x74); //灰底红字
// vga_write_str_color("[Pte Fault!]",0x74); //灰底红字
(*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2))) |= PG_P;
// disp_color_str("[Solved]",0x74);
// vga_write_str_color("[Solved]",0x74);
}
refresh_page_cache();
}
@ -309,7 +310,7 @@ int lin_mapping_phy(u32 AddrLin, //线性地址
if (pte_addr_phy < 0 || (pte_addr_phy & 0x3FF) != 0) // add by visual 2016.5.9
{
disp_color_str("lin_mapping_phy Error:pte_addr_phy", 0x74);
vga_write_str_color("lin_mapping_phy Error:pte_addr_phy", 0x74);
return -1;
}
@ -332,7 +333,7 @@ int lin_mapping_phy(u32 AddrLin, //线性地址
phy_addr = do_kmalloc_4k(); //从内核物理地址申请一页
else
{
// disp_str("%");
// kprintf("%");
phy_addr = do_malloc_4k(); //从用户物理地址空间申请一页
}
}
@ -349,7 +350,7 @@ int lin_mapping_phy(u32 AddrLin, //线性地址
if (phy_addr < 0 || (phy_addr & 0x3FF) != 0)
{
disp_color_str("lin_mapping_phy:phy_addr ERROR", 0x74);
vga_write_str_color("lin_mapping_phy:phy_addr ERROR", 0x74);
return -1;
}

View File

@ -12,6 +12,7 @@
#include "global.h"
#include "proto.h"
#include "string.h"
#include "stdio.h"
/* 本文件内函数声明 */
@ -270,29 +271,30 @@ static void init_descriptor(DESCRIPTOR * p_desc, u32 base, u32 limit, u16 attrib
};
/* 通过打印空格的方式清空屏幕的前五行,并把 disp_pos 清零 */
disp_pos = 0;
vga_set_disppos(0);
for(i=0;i<80*5;i++){
disp_str(" ");
kprintf(" ");
}
disp_pos = 0;
vga_set_disppos(0);
disp_color_str("Exception! --> ", text_color);
disp_color_str(err_description[vec_no], text_color);
disp_color_str("\n\n", text_color);
disp_color_str("EFLAGS:", text_color);
disp_int(eflags);
disp_color_str("CS:", text_color);
disp_int(cs);
disp_color_str("EIP:", text_color);
disp_int(eip);
vga_write_str_color("Exception! --> ", text_color);
vga_write_str_color(err_description[vec_no], text_color);
vga_write_str_color("\n\n", text_color);
vga_write_str_color("EFLAGS:", text_color);
kprintf("%d", eflags);
vga_write_str_color("CS:", text_color);
kprintf("%d", cs);
vga_write_str_color("EIP:", text_color);
kprintf("%d", eip);
if(err_code != 0xFFFFFFFF){
disp_color_str("Error code:", text_color);
disp_int(err_code);
vga_write_str_color("Error code:", text_color);
kprintf("%d", err_code);
}
//added by xw, 18/12/19
disp_str("\n");
kprintf("\n");
//added by xw, 18/12/19
p_proc_current->task.stat = KILLED;
@ -320,7 +322,7 @@ static void init_descriptor(DESCRIPTOR * p_desc, u32 base, u32 limit, u16 attrib
while (1)
{
disp_str("Loop in divide error handler...\n");
kprintf("Loop in divide error handler...\n");
i = 100;
while(--i){

View File

@ -27,16 +27,16 @@ int sys_pthread(void *entry)
/*if(p_proc_current->task.info.type == TYPE_THREAD )
{//线程不能创建线程
disp_color_str("[pthread failed:",0x74);
disp_color_str(p_proc_current->task.p_name,0x74);
disp_color_str("]",0x74);
vga_write_str_color("[pthread failed:",0x74);
vga_write_str_color(p_proc_current->task.p_name,0x74);
vga_write_str_color("]",0x74);
return -1;
}*/
/*****************申请空白PCB表**********************/
p_child = alloc_PCB();
if( 0==p_child )
{
disp_color_str("PCB NULL,pthread faild!",0x74);
vga_write_str_color("PCB NULL,pthread faild!",0x74);
return -1;
}
else
@ -78,9 +78,9 @@ int sys_pthread(void *entry)
/****************用户进程数+1****************************/
u_proc_sum += 1;
disp_color_str("[pthread success:",0x72);
disp_color_str(p_proc_current->task.p_name,0x72);
disp_color_str("]",0x72);
vga_write_str_color("[pthread success:",0x72);
vga_write_str_color(p_proc_current->task.p_name,0x72);
vga_write_str_color("]",0x72);
//anything child need is prepared now, set its state to ready. added by xw, 17/12/11
p_child->task.stat = READY;

View File

@ -57,6 +57,7 @@ _warn(const char *file, int line, const char *fmt,...)
*======================================================================*/
void cstart()
{
vga_set_disppos(0);
kprintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n-----\"cstart\" begins-----\n");
// 将 LOADER 中的 GDT 复制到新的 GDT 中

View File

@ -13,6 +13,7 @@
#include "global.h"
#include "proto.h"
#include "memman.h"
#include "stdio.h"
struct memfree *memarg = 0;
@ -121,7 +122,7 @@ int sys_free_4k(void* AddrLin)
*======================================================================*/
void sys_udisp_int(int arg)
{
disp_int(arg);
kprintf("%d", arg);
return ;
}
@ -131,6 +132,6 @@ void sys_udisp_int(int arg)
*======================================================================*/
void sys_udisp_str(char *arg)
{
disp_str(arg);
kprintf(arg);
return ;
}

View File

@ -11,6 +11,7 @@
#include "proc.h"
#include "global.h"
#include "proto.h"
#include "stdio.h"
/*
* This syscall needs long time to finish, so we can use it
@ -21,7 +22,7 @@ void sys_print_E()
{
int i, j;
disp_str("E( ");
kprintf("E( ");
i = 100;
while(--i){
@ -29,7 +30,7 @@ void sys_print_E()
while(--j){}
}
disp_str(") ");
kprintf(") ");
}
/*
@ -41,7 +42,7 @@ void sys_print_F()
{
int i, j;
disp_str("F( ");
kprintf("F( ");
i = 100;
while(--i){
@ -49,5 +50,5 @@ void sys_print_F()
while(--j){}
}
disp_str(") ");
kprintf(") ");
}

View File

@ -99,9 +99,9 @@ void task_tty()
//设置第一个tty光标位置第一个tty需要特殊处理
disable_int();
outb(CRTC_ADDR_REG, CURSOR_H);
outb(CRTC_DATA_REG, ((disp_pos / 2) >> 8) & 0xFF);
outb(CRTC_DATA_REG, ((vga_get_disppos()) >> 8) & 0xFF);
outb(CRTC_ADDR_REG, CURSOR_L);
outb(CRTC_DATA_REG, (disp_pos / 2) & 0xFF);
outb(CRTC_DATA_REG, (vga_get_disppos()) & 0xFF);
enable_int();
//轮询

54
kernel/uart.c Normal file
View File

@ -0,0 +1,54 @@
#include "uart.h"
#include "x86.h"
#include "tty.h"
#include "const.h"
#include "type.h"
#include "assert.h"
#include "stdio.h"
#include "memman.h"
void put_irq_handler(int irq, irq_handler handler);
void enable_irq(int irq);
int init_serial() {
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
// Check if serial is faulty (i.e: not same byte as sent)
if(inb(PORT + 0) != 0xAE) {
assert(0);
return 1;
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
outb(PORT + 4, 0x0f);
return 0;
}
static inline int is_transmit_empty() {
return inb(PORT + 5) & 0x20;
}
static inline int serial_received() {
return inb(PORT + 5) & 1;
}
char read_serial() {
while (serial_received() == 0);
return inb(PORT);
}
void write_serial(char a) {
while (is_transmit_empty() == 0);
outb(PORT,a);
}

View File

@ -6,6 +6,7 @@ LIB_OBJS := lib/string.o \
lib/kprintf.o \
lib/scanf.o \
lib/printfmt.o \
lib/vga_display.o \
LIB_OBJS := $(patsubst %, $(OBJDIR)/%, $(LIB_OBJS))

View File

@ -1,75 +0,0 @@
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
klib.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include "type.h"
#include "const.h"
#include "protect.h"
#include "string.h"
#include "proc.h"
#include "global.h"
#include "proto.h"
/*======================================================================*
itoa
*======================================================================*/
char * itoa(char * str, int num)/* 数字前面的 0 不被显示出来, 比如 0000B800 被显示成 B800 */
{
char * p = str;
char ch;
int i;
int flag = FALSE;
*p++ = '0';
*p++ = 'x';
if(num == 0){
*p++ = '0';
}
else{
for(i=28;i>=0;i-=4){
ch = (num >> i) & 0xF;
if(flag || (ch > 0)){
flag = TRUE;
ch += '0';
if(ch > '9'){
ch += 7;
}
*p++ = ch;
}
}
}
*p = 0;
return str;
}
/*======================================================================*
disp_int
*======================================================================*/
void disp_int(int input)
{
char output[16];
itoa(output, input);
disp_str(output);
}
/*======================================================================*
delay
*======================================================================*/
void delay(int time)
{
int i, j, k;
for(k=0;k<time;k++){
/*for(i=0;i<10000;i++){ for Virtual PC */
for(i=0;i<10;i++){/* for Bochs */
for(j=0;j<10000;j++){}
}
}
}

View File

@ -1,124 +0,0 @@
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; klib.asm
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Forrest Yu, 2005
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%include "sconst.inc"
; 导入全局变量
extern disp_pos
[SECTION .text]
; 导出函数
global disp_str
global disp_color_str
global write_char ; added by mingxuan 2019-5-19
; ========================================================================
; void disp_str(char * info);
; ========================================================================
disp_str:
push ebp
mov ebp, esp
pushad
mov esi, [ebp + 8] ; pszInfo
mov edi, [disp_pos]
mov ah, 0Fh
.1:
lodsb
test al, al
jz .2
cmp al, 0Ah ; 是回车吗?
jnz .3
push eax
mov eax, edi
mov bl, 160
div bl
and eax, 0FFh
inc eax
mov bl, 160
mul bl
mov edi, eax
pop eax
jmp .1
.3:
;added by xw, 17/12/11
;added begin
cmp edi, 1F40h
jnz .4
mov edi, 0FA0h
.4:
;added end
mov [gs:edi], ax
add edi, 2
jmp .1
.2:
mov [disp_pos], edi
popad
pop ebp
ret
; ========================================================================
; void disp_color_str(char * info, int color);
; ========================================================================
disp_color_str:
push ebp
mov ebp, esp
pushad
mov esi, [ebp + 8] ; pszInfo
mov edi, [disp_pos]
mov ah, [ebp + 12] ; color
.1:
lodsb
test al, al
jz .2
cmp al, 0Ah ; 是回车吗?
jnz .3
push eax
mov eax, edi
mov bl, 160
div bl
and eax, 0FFh
inc eax
mov bl, 160
mul bl
mov edi, eax
pop eax
jmp .1
.3:
mov [gs:edi], ax
add edi, 2
jmp .1
.2:
mov [disp_pos], edi
popad
pop ebp
ret
; ========================================================================
; void write_char(char ch);
; ========================================================================
write_char:
push ebp
mov ebp,esp
mov esi,[ebp+8]
mov edi,[disp_pos]
push eax
mov eax,esi
mov ah, 0Fh
mov [gs:edi], ax
pop eax
pop ebp
ret

View File

@ -3,12 +3,12 @@
#include "proc.h"
#include "global.h"
#include "proto.h"
#include "uart.h"
static void
kprintfputch(int ch, void *b)
{
char buf[2]={(char)ch,'\0'};
disp_str(buf);
vga_write_char(ch, WHITE_CHAR);
}
int
@ -30,5 +30,30 @@ kprintf(const char *fmt, ...)
rc = vkprintf(fmt, ap);
va_end(ap);
return rc;
}
static void
uart_putch(int ch, void *b) {
write_serial(ch);
}
int
v_uart_kprintf(const char *fmt, va_list ap)
{
vprintfmt((void*)uart_putch, NULL, fmt, ap);
return 0;
}
int uart_kprintf(const char *fmt, ...)
{
va_list ap;
int rc;
va_start(ap, fmt);
rc = v_uart_kprintf(fmt, ap);
va_end(ap);
return rc;
}

100
lib/vga_display.c Normal file
View File

@ -0,0 +1,100 @@
#include "tty.h"
#include "x86.h"
#include "console.h"
#include "const.h"
#include "assert.h"
/*****************************************************************************
Set the position of cursor in the screen
@param position the position in the linear array of video buffer
*/
static inline void vga_set_cursor(unsigned int position)
{
disable_int();
outb(CRTC_ADDR_REG, CURSOR_H);
outb(CRTC_DATA_REG, (position >> 8) & 0xFF);
outb(CRTC_ADDR_REG, CURSOR_L);
outb(CRTC_DATA_REG, position & 0xFF);
enable_int();
}
/*****************************************************************************
Disable the blinking cursor
*/
static inline void vga_disable_cursor()
{
outb(CRTC_ADDR_REG, 0x0A);
outb(CRTC_DATA_REG, 0x20);
}
/*****************************************************************************
Enable the blinking cursor, and set the height of the cursor
The cursor is splited into 16 units
@param cursor_start the start unit index
@param cursor_end the ending unit index
*/
static inline void vga_enable_cursor(u8 cursor_start, u8 cursor_end)
{
outb(0x3D4, 0x0A);
outb(0x3D5, (inb(0x3D5) & 0xC0) | cursor_start);
outb(0x3D4, 0x0B);
outb(0x3D5, (inb(0x3D5) & 0xE0) | cursor_end);
}
/*****************************************************************************
Write data directly to Video Memory cell
@param pos text mode position(pos*2 yourself)
@param dat data to be written, with format [ BG | FG | ASCII ]
*/
static inline void vga_put_raw(u32 pos, u16 dat)
{
u16 *pch = (u16 *)K_PHY2LIN(V_MEM_BASE + pos);
*pch = dat;
}
static inline void vga_flush_blankline(int line_no)
{
u32 *dst = (u32 *)K_PHY2LIN(V_MEM_BASE + line_no * SCR_WIDTH * 2);
for (int i = 0; i < SCR_WIDTH * sizeof(u16) / sizeof(u32); ++i)
{
*dst++ = (BLANK << 16) | BLANK;
}
}
static int disp_pos = 0;
void vga_set_disppos(int new_pos) {
disp_pos = new_pos;
}
int vga_get_disppos() {
return disp_pos;
}
/**********************************************************
* Write char to disp_pos and then increase disp_pos
* @param ch the character
* @param color the color, in 8-bit format
*/
void vga_write_char(const char ch, u16 color) {
if (ch == '\n') {
disp_pos = (disp_pos / SCR_WIDTH + 1) * SCR_WIDTH;
}
else {
vga_put_raw(disp_pos * 2, (color << 8) | (u16)ch);
disp_pos ++;
}
vga_set_cursor(disp_pos);
}
void vga_write_str(const char * str) {
for (char* s = (char *)str; *s; ++s) {
vga_write_char(*s, WHITE_CHAR);
}
}
void vga_write_str_color(const char * str, u8 color) {
for (char* s = (char *)str; *s; ++s) {
vga_write_char(*s, color);
}
}