From c40f00c80e8f9df7adb02e1aec45045f37729e55 Mon Sep 17 00:00:00 2001 From: xiaoxiao <1010386862@qq.com> Date: Mon, 2 Jan 2023 13:06:27 +0800 Subject: [PATCH] delete disp_* --- include/const.h | 264 ++++++++++++++++++++++----------------------- include/proto.h | 149 ++++++++++++------------- include/stdio.h | 92 ++++++++-------- kernel/Makefrag | 1 - kernel/console.c | 2 - kernel/global.c | 36 +++---- kernel/kernel.asm | 2 - kernel/ktest.c | 3 +- kernel/main.c | 6 -- kernel/syscall.asm | 57 +++------- kernel/syscallc.c | 132 ++++++++++------------- lib/klib.c | 57 +++++----- lib/kliba.asm | 124 --------------------- user/test.c | 3 +- 14 files changed, 362 insertions(+), 566 deletions(-) delete mode 100644 lib/kliba.asm diff --git a/include/const.h b/include/const.h index ea8fc01..cd676a0 100644 --- a/include/const.h +++ b/include/const.h @@ -1,16 +1,16 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - const.h + const.h ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Forrest Yu, 2005 + Forrest Yu, 2005 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -#ifndef _ORANGES_CONST_H_ -#define _ORANGES_CONST_H_ +#ifndef _ORANGES_CONST_H_ +#define _ORANGES_CONST_H_ /*最大整数定义*/ -#define MAX_UNSIGNED_INT 0xFFFFFFFF //最大的无符号整形 -#define MAX_INT 0x7FFFFFFF //最大的整形数 +#define MAX_UNSIGNED_INT 0xFFFFFFFF // 最大的无符号整形 +#define MAX_INT 0x7FFFFFFF // 最大的整形数 /* Color */ /* @@ -18,170 +18,170 @@ * MAKE_COLOR(BLACK, RED) | BRIGHT * MAKE_COLOR(BLACK, RED) | BRIGHT | FLASH */ -//added by mingxuan 2019-5-19 -#define BLACK 0x0 /* 0000 */ -#define BLUE 0x1 /* 0001 */ -#define GREEN 0x2 /* 0010 */ -#define CYAN 0x3 -#define RED 0x4 /* 0100 */ -#define MAGENTA 0x5 -#define BROWN 0x6 /* yellow = bright brown, which is 0xe*/ -#define WHITE 0x7 /* 0111 actually its light grey, white = bright light grey*/ -#define FLASH 0x80 /* 1000 0000 */ -#define BRIGHT 0x08 /* 0000 1000 */ -#define MAKE_COLOR(x,y) ((x<<4) | y) /* MAKE_COLOR(Background,Foreground) */ +// added by mingxuan 2019-5-19 +#define BLACK 0x0 /* 0000 */ +#define BLUE 0x1 /* 0001 */ +#define GREEN 0x2 /* 0010 */ +#define CYAN 0x3 +#define RED 0x4 /* 0100 */ +#define MAGENTA 0x5 +#define BROWN 0x6 /* yellow = bright brown, which is 0xe*/ +#define WHITE 0x7 /* 0111 actually its light grey, white = bright light grey*/ +#define FLASH 0x80 /* 1000 0000 */ +#define BRIGHT 0x08 /* 0000 1000 */ +#define MAKE_COLOR(x, y) ((x << 4) | y) /* MAKE_COLOR(Background,Foreground) */ /* Boolean */ -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 /* GDT 和 IDT 中描述符的个数 */ -#define GDT_SIZE 128 -#define IDT_SIZE 256 +#define GDT_SIZE 128 +#define IDT_SIZE 256 /* 权限 */ -#define PRIVILEGE_KRNL 0 -#define PRIVILEGE_TASK 1 -#define PRIVILEGE_USER 3 +#define PRIVILEGE_KRNL 0 +#define PRIVILEGE_TASK 1 +#define PRIVILEGE_USER 3 /* RPL */ -#define RPL_KRNL SA_RPL0 -#define RPL_TASK SA_RPL1 -#define RPL_USER SA_RPL3 +#define RPL_KRNL SA_RPL0 +#define RPL_TASK SA_RPL1 +#define RPL_USER SA_RPL3 /* 8259A interrupt controller ports. */ -#define INT_M_CTL 0x20 /* I/O port for interrupt controller */ -#define INT_M_CTLMASK 0x21 /* setting bits in this port disables ints */ -#define INT_S_CTL 0xA0 /* I/O port for second interrupt controller */ -#define INT_S_CTLMASK 0xA1 /* setting bits in this port disables ints */ +#define INT_M_CTL 0x20 /* I/O port for interrupt controller */ +#define INT_M_CTLMASK 0x21 /* setting bits in this port disables ints */ +#define INT_S_CTL 0xA0 /* I/O port for second interrupt controller */ +#define INT_S_CTLMASK 0xA1 /* setting bits in this port disables ints */ /* 8253/8254 PIT (Programmable Interval Timer) */ -#define TIMER0 0x40 /* I/O port for timer channel 0 */ -#define TIMER_MODE 0x43 /* I/O port for timer mode control */ -#define RATE_GENERATOR 0x34 /* 00-11-010-0 : - * Counter0 - LSB then MSB - rate generator - binary - */ -#define TIMER_FREQ 1193182L/* clock frequency for timer in PC and AT */ -#define HZ 100 /* clock freq (software settable on IBM-PC) */ +#define TIMER0 0x40 /* I/O port for timer channel 0 */ +#define TIMER_MODE 0x43 /* I/O port for timer mode control */ +#define RATE_GENERATOR 0x34 /* 00-11-010-0 : \ + * Counter0 - LSB then MSB - rate generator - binary \ + */ +#define TIMER_FREQ 1193182L /* clock frequency for timer in PC and AT */ +#define HZ 100 /* clock freq (software settable on IBM-PC) */ /* Hardware interrupts */ -#define NR_IRQ 16 /* Number of IRQs */ -#define CLOCK_IRQ 0 -#define KEYBOARD_IRQ 1 -#define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */ -#define ETHER_IRQ 3 /* default ethernet interrupt vector */ -#define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */ -#define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */ -#define XT_WINI_IRQ 5 /* xt winchester */ -#define FLOPPY_IRQ 6 /* floppy disk */ -#define PRINTER_IRQ 7 -#define AT_WINI_IRQ 14 /* at winchester */ -#define MOUSE_IRQ 12 //added by mingxuan 2019-5-19 +#define NR_IRQ 16 /* Number of IRQs */ +#define CLOCK_IRQ 0 +#define KEYBOARD_IRQ 1 +#define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */ +#define ETHER_IRQ 3 /* default ethernet interrupt vector */ +#define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */ +#define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */ +#define XT_WINI_IRQ 5 /* xt winchester */ +#define FLOPPY_IRQ 6 /* floppy disk */ +#define PRINTER_IRQ 7 +#define AT_WINI_IRQ 14 /* at winchester */ +#define MOUSE_IRQ 12 // added by mingxuan 2019-5-19 /* system call */ -//#define NR_SYS_CALL 23 //last modified by xw, 18/6/19 -#define NR_SYS_CALL 28 //modified by mingxuan 2019-5-17 +// #define NR_SYS_CALL 23 //last modified by xw, 18/6/19 +#define NR_SYS_CALL 26 // modified by mingxuan 2019-5-17 /* TTY */ -//added by mingxuan 2019-5-19 -#define NR_CONSOLES 3 /* consoles */ +// added by mingxuan 2019-5-19 +#define NR_CONSOLES 3 /* consoles */ /*页表相关*/ -#define PageTblNumAddr 0x500 //页表数量放在这个位置,必须与load.inc中一致 add by visual 2016.5.11 -#define KernelPageTblAddr 0x200000 //内核页表物理地址,必须与load.inc中一致 add by visual 2016.5.17 -/*线性地址描述*/ //edit by visual 2016.5.25 -#define KernelSize 0x800000 //内核的大小//add by visual 2016.5.10 -#define K_PHY2LIN(x) ((x)+0xC0000000) //内核中物理地址转线性地址 //add by visual 2016.5.10 -#define K_LIN2PHY(x) ((x)-0xC0000000) //added by xw, 18/8/27 -#define num_4B 0x4 //4B大小 -#define num_1K 0x400 //1k大小 -#define num_4K 0x1000 //4k大小 -#define num_4M 0x400000 //4M大小 -#define TextLinBase ((u32)0x0) //进程代码的起始地址,这是参考值,具体以elf描述为准 -#define TextLinLimitMAX (TextLinBase+0x20000000) //大小:512M,这是参考值,具体以elf描述为准, -#define DataLinBase TextLinLimitMAX //进程数据的起始地址,这是参考值,具体以elf描述为准 -#define DataLinLimitMAX (DataLinBase+0x20000000) //大小:512M,这是参考值,具体以elf描述为准,但是代码和数据长度总和不能超过这个值 -#define VpageLinBase DataLinLimitMAX //保留内存起始地址 -#define VpageLinLimitMAX (VpageLinBase+0x8000000-num_4K) //大小:128M-4k -#define SharePageBase VpageLinLimitMAX //共享页线性地址,执行fork\pthread的时候用,共享页必须4K对齐 -#define SharePageLimit (SharePageBase+num_4K) //大小:4k -#define HeapLinBase SharePageLimit //堆的起始地址 -#define HeapLinLimitMAX (HeapLinBase+0x40000000) //大小:1G -#define StackLinLimitMAX HeapLinLimitMAX //栈的大小: 1G-128M-4K(注意栈的基址和界限方向) -#define StackLinBase (ArgLinBase-num_4B) //=(StackLinLimitMAX+1G-128M-4K-4B)栈的起始地址,放在参数位置之前(注意堆栈的增长方向) -#define ArgLinBase (KernelLinBase-0x1000) //参数存放位置起始地址,放在3G前,暂时还没没用到 -#define ArgLinLimitMAX KernelLinBase //=(ArgLinBase+0x1000)大小:4K。 -#define KernelLinBase 0xC0000000 //内核线性起始地址(有0x30400的偏移) -#define KernelLinLimitMAX (KernelLinBase+0x40000000) //大小:1G +#define PageTblNumAddr 0x500 // 页表数量放在这个位置,必须与load.inc中一致 add by visual 2016.5.11 +#define KernelPageTblAddr 0x200000 // 内核页表物理地址,必须与load.inc中一致 add by visual 2016.5.17 +/*线性地址描述*/ // edit by visual 2016.5.25 +#define KernelSize 0x800000 // 内核的大小//add by visual 2016.5.10 +#define K_PHY2LIN(x) ((x) + 0xC0000000) // 内核中物理地址转线性地址 //add by visual 2016.5.10 +#define K_LIN2PHY(x) ((x)-0xC0000000) // added by xw, 18/8/27 +#define num_4B 0x4 // 4B大小 +#define num_1K 0x400 // 1k大小 +#define num_4K 0x1000 // 4k大小 +#define num_4M 0x400000 // 4M大小 +#define TextLinBase ((u32)0x0) // 进程代码的起始地址,这是参考值,具体以elf描述为准 +#define TextLinLimitMAX (TextLinBase + 0x20000000) // 大小:512M,这是参考值,具体以elf描述为准, +#define DataLinBase TextLinLimitMAX // 进程数据的起始地址,这是参考值,具体以elf描述为准 +#define DataLinLimitMAX (DataLinBase + 0x20000000) // 大小:512M,这是参考值,具体以elf描述为准,但是代码和数据长度总和不能超过这个值 +#define VpageLinBase DataLinLimitMAX // 保留内存起始地址 +#define VpageLinLimitMAX (VpageLinBase + 0x8000000 - num_4K) // 大小:128M-4k +#define SharePageBase VpageLinLimitMAX // 共享页线性地址,执行fork\pthread的时候用,共享页必须4K对齐 +#define SharePageLimit (SharePageBase + num_4K) // 大小:4k +#define HeapLinBase SharePageLimit // 堆的起始地址 +#define HeapLinLimitMAX (HeapLinBase + 0x40000000) // 大小:1G +#define StackLinLimitMAX HeapLinLimitMAX // 栈的大小: 1G-128M-4K(注意栈的基址和界限方向) +#define StackLinBase (ArgLinBase - num_4B) //=(StackLinLimitMAX+1G-128M-4K-4B)栈的起始地址,放在参数位置之前(注意堆栈的增长方向) +#define ArgLinBase (KernelLinBase - 0x1000) // 参数存放位置起始地址,放在3G前,暂时还没没用到 +#define ArgLinLimitMAX KernelLinBase //=(ArgLinBase+0x1000)大小:4K。 +#define KernelLinBase 0xC0000000 // 内核线性起始地址(有0x30400的偏移) +#define KernelLinLimitMAX (KernelLinBase + 0x40000000) // 大小:1G /***************目前线性地址布局***************************** edit by visual 2016.5.25 -* 进程代码 0 ~ 512M ,限制大小为512M -* 进程数据 512M ~ 1G,限制大小为512M -* 进程保留内存(以后可能存放虚页表和其他一些信息) 1G ~ 1G+128M,限制大小为128M,共享页放在这个位置 -* 进程堆 1G+128M ~ 2G+128M,限制大小为1G -* 进程栈 2G+128M ~ 3G-4K,限制大小为 1G-128M-4K -* 进程参数 3G-4K~3G,限制大小为4K -* 内核 3G~4G,限制大小为1G -***********************************************************/ + * 进程代码 0 ~ 512M ,限制大小为512M + * 进程数据 512M ~ 1G,限制大小为512M + * 进程保留内存(以后可能存放虚页表和其他一些信息) 1G ~ 1G+128M,限制大小为128M,共享页放在这个位置 + * 进程堆 1G+128M ~ 2G+128M,限制大小为1G + * 进程栈 2G+128M ~ 3G-4K,限制大小为 1G-128M-4K + * 进程参数 3G-4K~3G,限制大小为4K + * 内核 3G~4G,限制大小为1G + ***********************************************************/ -//#define ShareTblLinAddr (KernelLinLimitMAX-0x1000) //公共临时共享页,放在内核最后一个页表的最后一项上 - -/*分页机制常量的定义,必须与load.inc中一致*/ //add by visual 2016.4.5 -#define PG_P 1 // 页存在属性位 -#define PG_RWR 0 // R/W 属性位值, 读/执行 -#define PG_RWW 2 // R/W 属性位值, 读/写/执行 -#define PG_USS 0 // U/S 属性位值, 系统级 -#define PG_USU 4 // U/S 属性位值, 用户级 -#define PG_PS 64 // PS属性位值,4K页 +// #define ShareTblLinAddr (KernelLinLimitMAX-0x1000) //公共临时共享页,放在内核最后一个页表的最后一项上 + +/*分页机制常量的定义,必须与load.inc中一致*/ // add by visual 2016.4.5 +#define PG_P 1 // 页存在属性位 +#define PG_RWR 0 // R/W 属性位值, 读/执行 +#define PG_RWW 2 // R/W 属性位值, 读/写/执行 +#define PG_USS 0 // U/S 属性位值, 系统级 +#define PG_USU 4 // U/S 属性位值, 用户级 +#define PG_PS 64 // PS属性位值,4K页 /* AT keyboard */ /* 8042 ports */ -//added by mingxuan 2019-5-19 -#define KB_DATA 0x60 /* I/O port for keyboard data - * Read : Read Output Buffer - * Write: Write Input Buffer - * (8042 Data & 8048 Command) - */ -#define KB_CMD 0x64 /* I/O port for keyboard command - * Read : Read Status Register - * Write: Write Input Buffer - * (8042 Command) - */ -#define KB_STA 0x64 -#define KEYSTA_SEND_NOTREADY 0x02 -#define KBSTATUS_IBF 0x02 -#define KBSTATUS_OBF 0x01 +// added by mingxuan 2019-5-19 +#define KB_DATA 0x60 /* I/O port for keyboard data \ + * Read : Read Output Buffer \ + * Write: Write Input Buffer \ + * (8042 Data & 8048 Command) \ + */ +#define KB_CMD 0x64 /* I/O port for keyboard command \ + * Read : Read Status Register \ + * Write: Write Input Buffer \ + * (8042 Command) \ + */ +#define KB_STA 0x64 +#define KEYSTA_SEND_NOTREADY 0x02 +#define KBSTATUS_IBF 0x02 +#define KBSTATUS_OBF 0x01 -#define wait_KB_write() while(in_byte(KB_STA) & KBSTATUS_IBF) -#define wait_KB_read() while(in_byte(KB_STA) & KBSTATUS_OBF) +#define wait_KB_write() while (in_byte(KB_STA) & KBSTATUS_IBF) +#define wait_KB_read() while (in_byte(KB_STA) & KBSTATUS_OBF) -#define KEYCMD_WRITE_MODE 0x60 -#define KBC_MODE 0x47 +#define KEYCMD_WRITE_MODE 0x60 +#define KBC_MODE 0x47 #define KEYCMD_SENDTO_MOUSE 0xd4 #define MOUSECMD_ENABLE 0xf4 #define KBCMD_EN_MOUSE_INTFACE 0xa8 -#define LED_CODE 0xED -#define KB_ACK 0xFA +#define LED_CODE 0xED +#define KB_ACK 0xFA /* VGA */ -//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 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) */ -#define CURSOR_L 0xF /* reg index of cursor position (LSB) */ -#define V_MEM_BASE 0xB8000 /* base of color video memory */ -#define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */ +// 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 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) */ +#define CURSOR_L 0xF /* reg index of cursor position (LSB) */ +#define V_MEM_BASE 0xB8000 /* base of color video memory */ +#define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */ #define STD_IN 0 #define STD_OUT 1 #define STD_ERR 2 /* max() & min() */ -//added by mingxuan 2019-5-19 -#define max(a,b) ((a) > (b) ? (a) : (b)) -#define min(a,b) ((a) < (b) ? (a) : (b)) -#define abs(a) ((a) < 0 ? -(a) : (a)) +// added by mingxuan 2019-5-19 +#define max(a, b) ((a) > (b) ? (a) : (b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define abs(a) ((a) < 0 ? -(a) : (a)) #endif /* _ORANGES_CONST_H_ */ diff --git a/include/proto.h b/include/proto.h index ae50a62..dc7a860 100644 --- a/include/proto.h +++ b/include/proto.h @@ -5,60 +5,54 @@ Forrest Yu, 2005 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -/* 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 - -//added by zcr -void disable_irq(int irq); -void enable_irq(int irq); -void init_8259A(); +// added by zcr +void disable_irq(int irq); +void enable_irq(int irq); +void init_8259A(); //~zcr /* protect.c */ -void init_prot(); -u32 seg2phys(u16 seg); +void init_prot(); +u32 seg2phys(u16 seg); /* klib.c */ -void delay(int time); +void delay(int time); /* kernel.asm */ -u32 read_cr2(); //add by visual 2016.5.9 -void refresh_page_cache(); //add by visual 2016.5.12 -//void restart_int(); -//void save_context(); -void restart_initial(); //added by xw, 18/4/18 -void restart_restore(); //added by xw, 18/4/20 -void sched(); //added by xw, 18/4/18 -void halt(); //added by xw, 18/6/11 -u32 get_arg(void *uesp, int order); //added by xw, 18/6/18 +u32 read_cr2(); // add by visual 2016.5.9 +void refresh_page_cache(); // add by visual 2016.5.12 +// void restart_int(); +// void save_context(); +void restart_initial(); // added by xw, 18/4/18 +void restart_restore(); // added by xw, 18/4/20 +void sched(); // added by xw, 18/4/18 +void halt(); // added by xw, 18/6/11 +u32 get_arg(void *uesp, int order); // added by xw, 18/6/18 /* ktest.c */ void initial(); /* keyboard.c */ -//added by mingxuan 2019-5-19 +// added by mingxuan 2019-5-19 void init_kb(); void keyboard_read(); /* tty.c */ -//added by mingxuan 2019-5-19 -void in_process(TTY* p_tty,u32 key); +// added by mingxuan 2019-5-19 +void in_process(TTY *p_tty, u32 key); void task_tty(); -void tty_write(NTTY* tty, char* buf, int len); -int tty_read(NTTY* tty, char* buf, int len); +void tty_write(NTTY *tty, char *buf, int len); +int tty_read(NTTY *tty, char *buf, int len); void init_tty_main(); -NTTY* get_tty(const int nr_tty); +NTTY *get_tty(const int nr_tty); /* printf.c */ -//added by mingxuan 2019-5-19 -int printf(const char *fmt, ...); +// added by mingxuan 2019-5-19 +int printf(const char *fmt, ...); /* vsprintf.c */ -//added by mingxuan 2019-5-19 -int vsprintf(char *buf, const char *fmt, va_list args); +// added by mingxuan 2019-5-19 +int vsprintf(char *buf, const char *fmt, va_list args); /* i8259.c */ void put_irq_handler(int irq, irq_handler handler); @@ -68,76 +62,71 @@ void spurious_irq(int irq); void clock_handler(int irq); /*************************************************************** -* 以下是系统调用相关函数的声明 -****************************************************************/ + * 以下是系统调用相关函数的声明 + ****************************************************************/ /* syscall.asm */ -void sys_call(); /* int_handler */ -int get_ticks(); -int get_pid(); //add by visual 2016.4.6 -void* kmalloc(int size); //edit by visual 2016.5.9 -void* kmalloc_4k(); //edit by visual 2016.5.9 -void* malloc(int size); //edit by visual 2016.5.9 -void* malloc_4k(); //edit by visual 2016.5.9 -int free(void *arg); //edit by visual 2016.5.9 -int free_4k(void* AdddrLin); //edit by visual 2016.5.9 -int fork(); //add by visual 2016.4.8 -int pthread(void *arg); //add by visual 2016.4.11 -void udisp_int(int arg); //add by visual 2016.5.16 -void udisp_str(char* arg); //add by visual 2016.5.16 -u32 exec(char* path); //add by visual 2016.5.16 -void yield(); //added by xw, 18/4/19 -void sleep(int n); //added by xw, 18/4/19 +void sys_call(); /* int_handler */ +int get_ticks(); +int get_pid(); // add by visual 2016.4.6 +void *kmalloc(int size); // edit by visual 2016.5.9 +void *kmalloc_4k(); // edit by visual 2016.5.9 +void *malloc(int size); // edit by visual 2016.5.9 +void *malloc_4k(); // edit by visual 2016.5.9 +int free(void *arg); // edit by visual 2016.5.9 +int free_4k(void *AdddrLin); // edit by visual 2016.5.9 +int fork(); // add by visual 2016.4.8 +int pthread(void *arg); // add by visual 2016.4.11 +u32 exec(char *path); // add by visual 2016.5.16 +void yield(); // added by xw, 18/4/19 +void sleep(int n); // added by xw, 18/4/19 void print_E(); void print_F(); -/* syscallc.c */ //edit by visual 2016.4.6 -int sys_get_ticks(); /* sys_call */ -int sys_get_pid(); //add by visual 2016.4.6 -void* sys_kmalloc(int size); //edit by visual 2016.5.9 -void* sys_kmalloc_4k(); //edit by visual 2016.5.9 -void* sys_malloc(int size); //edit by visual 2016.5.9 -void* sys_malloc_4k(); //edit by visual 2016.5.9 -int sys_free(void *arg); //edit by visual 2016.5.9 -int sys_free_4k(void* AdddrLin); //edit by visual 2016.5.9 -int sys_pthread(void *arg); //add by visual 2016.4.11 -void sys_udisp_int(int arg); //add by visual 2016.5.16 -void sys_udisp_str(char* arg); //add by visual 2016.5.16 +/* syscallc.c */ // edit by visual 2016.4.6 +int sys_get_ticks(); /* sys_call */ +int sys_get_pid(); // add by visual 2016.4.6 +void *sys_kmalloc(int size); // edit by visual 2016.5.9 +void *sys_kmalloc_4k(); // edit by visual 2016.5.9 +void *sys_malloc(int size); // edit by visual 2016.5.9 +void *sys_malloc_4k(); // edit by visual 2016.5.9 +int sys_free(void *arg); // edit by visual 2016.5.9 +int sys_free_4k(void *AdddrLin); // edit by visual 2016.5.9 +int sys_pthread(void *arg); // add by visual 2016.4.11 /* proc.c */ -PROCESS* alloc_PCB(); +PROCESS *alloc_PCB(); void free_PCB(PROCESS *p); void sys_yield(); void sys_sleep(int n); void sys_wakeup(void *channel); int ldt_seg_linear(PROCESS *p, int idx); -void* va2la(int pid, void* va); +void *va2la(int pid, void *va); /* testfunc.c */ void sys_print_E(); void sys_print_F(); /*exec.c*/ -u32 sys_exec(char* path); //add by visual 2016.5.23 +u32 sys_exec(char *path); // add by visual 2016.5.23 /*fork.c*/ -int sys_fork(); //add by visual 2016.5.25 +int sys_fork(); // add by visual 2016.5.25 /*************************************************************** -* 以上是系统调用相关函数的声明 -****************************************************************/ + * 以上是系统调用相关函数的声明 + ****************************************************************/ /*pagepte.c*/ -u32 init_page_pte(u32 pid); //edit by visual 2016.4.28 -void page_fault_handler(u32 vec_no, u32 err_code, u32 eip, u32 cs, u32 eflags);//add by visual 2016.4.19 -u32 get_pde_index(u32 AddrLin);//add by visual 2016.4.28 +u32 init_page_pte(u32 pid); // edit by visual 2016.4.28 +void page_fault_handler(u32 vec_no, u32 err_code, u32 eip, u32 cs, u32 eflags); // add by visual 2016.4.19 +u32 get_pde_index(u32 AddrLin); // add by visual 2016.4.28 u32 get_pte_index(u32 AddrLin); u32 get_pde_phy_addr(u32 pid); -u32 get_pte_phy_addr(u32 pid,u32 AddrLin); -u32 get_page_phy_addr(u32 pid,u32 AddrLin);//线性地址 -u32 pte_exist(u32 PageTblAddrPhy,u32 AddrLin); -u32 phy_exist(u32 PageTblPhyAddr,u32 AddrLin); -void write_page_pde(u32 PageDirPhyAddr,u32 AddrLin,u32 TblPhyAddr,u32 Attribute); -void write_page_pte( u32 TblPhyAddr,u32 AddrLin,u32 PhyAddr,u32 Attribute); +u32 get_pte_phy_addr(u32 pid, u32 AddrLin); +u32 get_page_phy_addr(u32 pid, u32 AddrLin); // 线性地址 +u32 pte_exist(u32 PageTblAddrPhy, u32 AddrLin); +u32 phy_exist(u32 PageTblPhyAddr, u32 AddrLin); +void write_page_pde(u32 PageDirPhyAddr, u32 AddrLin, u32 TblPhyAddr, u32 Attribute); +void write_page_pte(u32 TblPhyAddr, u32 AddrLin, u32 PhyAddr, u32 Attribute); u32 vmalloc(u32 size); -int lin_mapping_phy(u32 AddrLin,u32 phy_addr,u32 pid,u32 pde_Attribute,u32 pte_Attribute);//edit by visual 2016.5.19 -void clear_kernel_pagepte_low(); //add by visual 2016.5.12 - +int lin_mapping_phy(u32 AddrLin, u32 phy_addr, u32 pid, u32 pde_Attribute, u32 pte_Attribute); // edit by visual 2016.5.19 +void clear_kernel_pagepte_low(); // add by visual 2016.5.12 diff --git a/include/stdio.h b/include/stdio.h index 833d083..c0396fe 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,74 +1,72 @@ /******************************************** -*用户库函数声明 add by visual 2016.5.16 -*************************************************/ -#include "const.h" //added by mingxuan 2019-5-19 -#include "type.h" //added by mingxuan 2019-5-19 + *用户库函数声明 add by visual 2016.5.16 + *************************************************/ +#include "const.h" //added by mingxuan 2019-5-19 +#include "type.h" //added by mingxuan 2019-5-19 #include "stdarg.h" -#ifndef _STDIO_H_ //added by mingxuan 2019-5-19 -#define _STDIO_H_ //added by mingxuan 2019-5-19 +#ifndef _STDIO_H_ // added by mingxuan 2019-5-19 +#define _STDIO_H_ // added by mingxuan 2019-5-19 /*syscall.asm*/ int get_ticks(); -int get_pid(); -void* kmalloc(int size); -void* kmalloc_4k(); -void* malloc(int size); -void* malloc_4k(); -int free(void *arg); -int free_4k(void* AdddrLin); -int fork(); -int pthread(void *arg); -void udisp_int(int arg); -void udisp_str(char* arg); +int get_pid(); +void *kmalloc(int size); +void *kmalloc_4k(); +void *malloc(int size); +void *malloc_4k(); +int free(void *arg); +int free_4k(void *AdddrLin); +int fork(); +int pthread(void *arg); -//added by xw +// added by xw /* file system */ -#define MAX_FILENAME_LEN 12 -#define MAX_PATH 128 -#define O_CREAT 1 -#define O_RDWR 2 -#define SEEK_SET 1 -#define SEEK_CUR 2 -#define SEEK_END 3 +#define MAX_FILENAME_LEN 12 +#define MAX_PATH 128 +#define O_CREAT 1 +#define O_RDWR 2 +#define SEEK_SET 1 +#define SEEK_CUR 2 +#define SEEK_END 3 -int open(const char *pathname, int flags); //added by xw, 18/6/19 -int close(int fd); //added by xw, 18/6/19 -int read(int fd, void *buf, int count); //added by xw, 18/6/19 -int write(int fd, const void *buf, int count); //added by xw, 18/6/19 -int lseek(int fd, int offset, int whence); //added by xw, 18/6/19 -int unlink(const char *pathname); //added by xw, 18/6/19 +int open(const char *pathname, int flags); // added by xw, 18/6/19 +int close(int fd); // added by xw, 18/6/19 +int read(int fd, void *buf, int count); // added by xw, 18/6/19 +int write(int fd, const void *buf, int count); // added by xw, 18/6/19 +int lseek(int fd, int offset, int whence); // added by xw, 18/6/19 +int unlink(const char *pathname); // added by xw, 18/6/19 //~xw /*string.asm*/ -long strtol(const char *cp,char **endp,unsigned int base); +long strtol(const char *cp, char **endp, unsigned int base); /*printf.c*/ -//added by mingxuan 2019-5-19 +// added by mingxuan 2019-5-19 #define EOF -1 // #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) ) // #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) ) // #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) // #define va_end(ap) ( ap = (va_list)0 ) -#define isspace(s) (s==' ') +#define isspace(s) (s == ' ') #define TOLOWER(x) ((x) | 0x20) -#define isxdigit(c) (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F')) -#define isdigit(c) ('0' <= (c) && (c) <= '9') +#define isxdigit(c) (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F')) +#define isdigit(c) ('0' <= (c) && (c) <= '9') -void printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...); -void vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list); -int vsnprintf(char *buf, int n, const char *fmt, va_list ap); -int snprintf(char *buf, int n, const char *fmt, ...); +void printfmt(void (*putch)(int, void *), void *putdat, const char *fmt, ...); +void vprintfmt(void (*putch)(int, void *), void *putdat, const char *fmt, va_list); +int vsnprintf(char *buf, int n, const char *fmt, va_list ap); +int snprintf(char *buf, int n, const char *fmt, ...); -int vprintf(const char *fmt, va_list ap); -int printf(const char *fmt, ...); +int vprintf(const char *fmt, va_list ap); +int printf(const char *fmt, ...); -int vkprintf(const char *fmt, va_list ap); -int kprintf(const char *fmt, ...); +int vkprintf(const char *fmt, va_list ap); +int kprintf(const char *fmt, ...); // int scanf(char *str, ...); -char getchar(); //added by mingxuan 2019-5-23 -char* gets(char *str); //added by mingxuan 2019-5-23 +char getchar(); // added by mingxuan 2019-5-23 +char *gets(char *str); // added by mingxuan 2019-5-23 -#endif //added by mingxuan 2019-5-19 \ No newline at end of file +#endif // added by mingxuan 2019-5-19 \ No newline at end of file diff --git a/kernel/Makefrag b/kernel/Makefrag index d183bf6..fd64fba 100644 --- a/kernel/Makefrag +++ b/kernel/Makefrag @@ -33,7 +33,6 @@ KERN_SRCFILES :=kernel/kernel.asm \ kernel/serialport.c \ kernel/vga.c \ lib/klib.c \ - lib/kliba.asm \ KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES)) diff --git a/kernel/console.c b/kernel/console.c index 7d79065..79c4fef 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -97,7 +97,6 @@ void out_char(CONSOLE *con, char ch) //*(pch - 2) = ' '; //*(pch - 1) = DEFAULT_CHAR_COLOR; disp_pos = con->cursor * 2; - // write_char(' '); write_char_c(disp_pos, ' '); } break; @@ -105,7 +104,6 @@ void out_char(CONSOLE *con, char ch) //*pch++ = ch; //*pch++ = DEFAULT_CHAR_COLOR; disp_pos = con->cursor * 2; - // write_char(ch); write_char_c(disp_pos, ch); con->cursor++; diff --git a/kernel/global.c b/kernel/global.c index d5b43ae..5eee110 100644 --- a/kernel/global.c +++ b/kernel/global.c @@ -1,8 +1,8 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - global.c + global.c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Forrest Yu, 2005 + Forrest Yu, 2005 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* * To make things more direct. In the headers below, @@ -55,31 +55,29 @@ system_call sys_call_table[NR_SYS_CALL] = { sys_get_pid, // add by visual 2016.4.6 sys_kmalloc, // add by visual 2016.4.6 sys_kmalloc_4k, // add by visual 2016.4.7 - sys_malloc, // add by visual 2016.4.7 //5th + sys_malloc, // add by visual 2016.4.7 //5th sys_malloc_4k, // add by visual 2016.4.7 - sys_free, // add by visual 2016.4.7 + sys_free, // add by visual 2016.4.7 sys_free_4k, // add by visual 2016.4.7 - sys_fork, // add by visual 2016.4.8 + sys_fork, // add by visual 2016.4.8 sys_pthread, // add by visual 2016.4.11 //10th - sys_udisp_int, // add by visual 2016.5.16 - sys_udisp_str, // add by visual 2016.5.16 - sys_exec, // add by visual 2016.5.16 - sys_yield, // added by xw - sys_sleep, // added by xw //15th + sys_exec, // add by visual 2016.5.16 + sys_yield, // added by xw + sys_sleep, // added by xw //13th sys_print_E, // added by xw sys_print_F, // added by xw - sys_open, // added by xw, 18/6/18 - sys_close, // added by xw, 18/6/18 - sys_read, // added by xw, 18/6/18 //20th - sys_write, // added by xw, 18/6/18 - sys_lseek, // added by xw, 18/6/18 - sys_unlink, // added by xw, 18/6/19 //23th - sys_create, // added by mingxuan 2019-5-17 - sys_delete, // added by mingxuan 2019-5-17 + sys_open, // added by xw, 18/6/18 + sys_close, // added by xw, 18/6/18 + sys_read, // added by xw, 18/6/18 //18th + sys_write, // added by xw, 18/6/18 + sys_lseek, // added by xw, 18/6/18 + sys_unlink, // added by xw, 18/6/19 //21th + sys_create, // added by mingxuan 2019-5-17 + sys_delete, // added by mingxuan 2019-5-17 sys_opendir, // added by mingxuan 2019-5-17 sys_createdir, // added by mingxuan 2019-5-17 sys_deletedir // added by mingxuan 2019-5-17 }; -TTY tty_table[NR_CONSOLES]; // added by mingxuan 2019-5-19 +TTY tty_table[NR_CONSOLES]; // added by mingxuan 2019-5-19 CONSOLE console_table[NR_CONSOLES]; // added by mingxuan 2019-5-19 \ No newline at end of file diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 5e079f7..df1e02d 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -14,12 +14,10 @@ extern kernel_main 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 diff --git a/kernel/ktest.c b/kernel/ktest.c index 44723f1..43c4391 100644 --- a/kernel/ktest.c +++ b/kernel/ktest.c @@ -132,8 +132,7 @@ void initial() do_vclose(stdout); do_vclose(stderr); - // exec("orange/shell_1.bin"); - exec("orange/test.bin"); + exec("orange/shell_1.bin"); while (1) ; diff --git a/kernel/main.c b/kernel/main.c index 8a01d8c..972f997 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -37,12 +37,6 @@ int kernel_main() init_serial(); int error; - // disp_pos = 0; - // for (int i = 0; i < 25; i++) { - // for (int j = 0; j < 80; j++) { - // disp_str(" "); - // } - // } disp_pos = 0; // kprintf("-----Kernel Initialization Begins-----\n"); diff --git a/kernel/syscall.asm b/kernel/syscall.asm index c1fe58c..dcb9473 100644 --- a/kernel/syscall.asm +++ b/kernel/syscall.asm @@ -17,26 +17,24 @@ _NR_free equ 6 ; //add by visual 2016.4.7 _NR_free_4k equ 7 ; //add by visual 2016.4.7 _NR_fork equ 8 ; //add by visual 2016.4.8 _NR_pthread equ 9 ; //add by visual 2016.4.11 -_NR_udisp_int equ 10 ; //add by visual 2016.5.16 -_NR_udisp_str equ 11 ; //add by visual 2016.5.16 -_NR_exec equ 12 ; //add by visual 2016.5.16 -_NR_yield equ 13 ; //added by xw, 17/12 -_NR_sleep equ 14 ; //added by xw, 17/12 -_NR_print_E equ 15 ; //added by xw, 18/4/27 -_NR_print_F equ 16 ; //added by xw, 18/4/27 +_NR_exec equ 10 ; //add by visual 2016.5.16 +_NR_yield equ 11 ; //added by xw, 17/12 +_NR_sleep equ 12 ; //added by xw, 17/12 +_NR_print_E equ 13 ; //added by xw, 18/4/27 +_NR_print_F equ 14 ; //added by xw, 18/4/27 -_NR_open equ 17 ; //added by xw, 18/6/18 -_NR_close equ 18 ; //added by xw, 18/6/18 -_NR_read equ 19 ; //added by xw, 18/6/18 -_NR_write equ 20 ; //added by xw, 18/6/18 -_NR_lseek equ 21 ; //added by xw, 18/6/18 -_NR_unlink equ 22 ; //added by xw, 18/6/18 +_NR_open equ 15 ; //added by xw, 18/6/18 +_NR_close equ 16 ; //added by xw, 18/6/18 +_NR_read equ 17 ; //added by xw, 18/6/18 +_NR_write equ 18 ; //added by xw, 18/6/18 +_NR_lseek equ 19 ; //added by xw, 18/6/18 +_NR_unlink equ 20 ; //added by xw, 18/6/18 -_NR_create equ 23 ; //added by mingxuan 2019-5-17 -_NR_delete equ 24 ; //added by mingxuan 2019-5-17 -_NR_opendir equ 25 ; //added by mingxuan 2019-5-17 -_NR_createdir equ 26 ; //added by mingxuan 2019-5-17 -_NR_deletedir equ 27 ; //added by mingxuan 2019-5-17 +_NR_create equ 21 ; //added by mingxuan 2019-5-17 +_NR_delete equ 22 ; //added by mingxuan 2019-5-17 +_NR_opendir equ 22 ; //added by mingxuan 2019-5-17 +_NR_createdir equ 24 ; //added by mingxuan 2019-5-17 +_NR_deletedir equ 25 ; //added by mingxuan 2019-5-17 INT_VECTOR_SYS_CALL equ 0x90 @@ -51,8 +49,6 @@ global free ; //add by visual 2016.4.7 global free_4k ; //add by visual 2016.4.7 global fork ; //add by visual 2016.4.8 global pthread ; //add by visual 2016.4.11 -global udisp_int ; //add by visual 2016.5.16 -global udisp_str ; //add by visual 2016.5.16 global exec ; //add by visual 2016.5.16 global yield ; //added by xw global sleep ; //added by xw @@ -175,27 +171,6 @@ pthread: pop ebx ret -; ==================================================================== -; udisp_int //add by visual 2016.5.16 -; ==================================================================== -udisp_int: - push ebx - mov ebx,[esp+8] - mov eax, _NR_udisp_int - int INT_VECTOR_SYS_CALL - pop ebx - ret - -; ==================================================================== -; udisp_str //add by visual 2016.5.16 -; ==================================================================== -udisp_str: - push ebx - mov ebx,[esp+8] - mov eax, _NR_udisp_str - int INT_VECTOR_SYS_CALL - pop ebx - ret ; ==================================================================== ; exec //add by visual 2016.5.16 diff --git a/kernel/syscallc.c b/kernel/syscallc.c index 890f1a0..9039235 100644 --- a/kernel/syscallc.c +++ b/kernel/syscallc.c @@ -1,9 +1,9 @@ /********************************************************* -*系统调用具体函数的实现 -* -* -* -**********************************************************/ + *系统调用具体函数的实现 + * + * + * + **********************************************************/ #include "type.h" #include "const.h" @@ -17,16 +17,15 @@ struct memfree *memarg = 0; /*======================================================================* - sys_get_ticks add by visual 2016.4.6 + sys_get_ticks add by visual 2016.4.6 *======================================================================*/ int sys_get_ticks() { return ticks; } - /*======================================================================* - sys_get_pid add by visual 2016.4.6 + sys_get_pid add by visual 2016.4.6 *======================================================================*/ int sys_get_pid() { @@ -34,103 +33,80 @@ int sys_get_pid() } /*======================================================================* - sys_kmalloc add by visual 2016.4.6 + sys_kmalloc add by visual 2016.4.6 *======================================================================*/ -void* sys_kmalloc(int size) -{ //edit by visual 2015.5.9 - return (void*)(do_kmalloc(size)); +void *sys_kmalloc(int size) +{ // edit by visual 2015.5.9 + return (void *)(do_kmalloc(size)); } /*======================================================================* - sys_kmalloc_4k add by visual 2016.4.7 + sys_kmalloc_4k add by visual 2016.4.7 *======================================================================*/ -void* sys_kmalloc_4k() -{ - return (void*)(do_kmalloc_4k()); +void *sys_kmalloc_4k() +{ + return (void *)(do_kmalloc_4k()); } - + /*======================================================================* - sys_malloc edit by visual 2016.5.4 + sys_malloc edit by visual 2016.5.4 *======================================================================*/ -void* sys_malloc(int size) -{ - int vir_addr,AddrLin; +void *sys_malloc(int size) +{ + int vir_addr, AddrLin; vir_addr = vmalloc(size); - - for( AddrLin=vir_addr; AddrLintask.pid,//进程pid //edit by visual 2016.5.19 - PG_P | PG_USU | PG_RWW,//页目录的属性位 - PG_P | PG_USU | PG_RWW);//页表的属性位 + lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9 + MAX_UNSIGNED_INT, // 物理地址 //edit by visual 2016.5.19 + p_proc_current->task.pid, // 进程pid //edit by visual 2016.5.19 + PG_P | PG_USU | PG_RWW, // 页目录的属性位 + PG_P | PG_USU | PG_RWW); // 页表的属性位 } - return (void*)vir_addr; + return (void *)vir_addr; } - /*======================================================================* - sys_malloc_4k edit by visual 2016.5.4 + sys_malloc_4k edit by visual 2016.5.4 *======================================================================*/ -void* sys_malloc_4k() -{ - int vir_addr,AddrLin; +void *sys_malloc_4k() +{ + int vir_addr, AddrLin; vir_addr = vmalloc(num_4K); - - for( AddrLin=vir_addr; AddrLintask.pid,//进程pid //edit by visual 2016.5.19 - PG_P | PG_USU | PG_RWW,//页目录的属性位 - PG_P | PG_USU | PG_RWW);//页表的属性位 + lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9 + MAX_UNSIGNED_INT, // 物理地址 + p_proc_current->task.pid, // 进程pid //edit by visual 2016.5.19 + PG_P | PG_USU | PG_RWW, // 页目录的属性位 + PG_P | PG_USU | PG_RWW); // 页表的属性位 } - return (void*)vir_addr; + return (void *)vir_addr; } - /*======================================================================* - sys_free add by visual 2016.4.7 + sys_free add by visual 2016.4.7 *======================================================================*/ int sys_free(void *arg) -{ +{ memarg = (struct memfree *)arg; - return do_free(memarg->addr,memarg->size); + return do_free(memarg->addr, memarg->size); } /*======================================================================* - sys_free_4k edit by visual 2016.5.9 + sys_free_4k edit by visual 2016.5.9 *======================================================================*/ -int sys_free_4k(void* AddrLin) -{//线性地址可以不释放,但是页表映射关系必须清除! - int phy_addr; //add by visual 2016.5.9 - - phy_addr = get_page_phy_addr(p_proc_current->task.pid,(int)AddrLin);//获取物理页的物理地址 //edit by visual 2016.5.19 - lin_mapping_phy( (int)AddrLin,//线性地址 - phy_addr,//物理地址 - p_proc_current->task.pid,//进程pid //edit by visual 2016.5.19 - PG_P | PG_USU | PG_RWW,//页目录的属性位 - 0 | PG_USU | PG_RWW);//页表的属性位 +int sys_free_4k(void *AddrLin) +{ // 线性地址可以不释放,但是页表映射关系必须清除! + int phy_addr; // add by visual 2016.5.9 + + phy_addr = get_page_phy_addr(p_proc_current->task.pid, (int)AddrLin); // 获取物理页的物理地址 //edit by visual 2016.5.19 + lin_mapping_phy((int)AddrLin, // 线性地址 + phy_addr, // 物理地址 + p_proc_current->task.pid, // 进程pid //edit by visual 2016.5.19 + PG_P | PG_USU | PG_RWW, // 页目录的属性位 + 0 | PG_USU | PG_RWW); // 页表的属性位 return do_free_4k(phy_addr); } - - -/*======================================================================* - sys_udisp_int add by visual 2016.5.16 -用户用的打印函数 - *======================================================================*/ -void sys_udisp_int(int arg) -{ - disp_int(arg); - return ; -} - -/*======================================================================* - sys_udisp_str add by visual 2016.5.16 -用户用的打印函数 - *======================================================================*/ -void sys_udisp_str(char *arg) -{ - disp_str(arg); - return ; -} \ No newline at end of file diff --git a/lib/klib.c b/lib/klib.c index 7c443e3..a47a392 100644 --- a/lib/klib.c +++ b/lib/klib.c @@ -1,8 +1,8 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - klib.c + klib.c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Forrest Yu, 2005 + Forrest Yu, 2005 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #include "type.h" @@ -13,30 +13,34 @@ #include "global.h" #include "proto.h" - /*======================================================================* - itoa + itoa *======================================================================*/ - char * itoa(char * str, int num)/* 数字前面的 0 不被显示出来, 比如 0000B800 被显示成 B800 */ +char *itoa(char *str, int num) /* 数字前面的 0 不被显示出来, 比如 0000B800 被显示成 B800 */ { - char * p = str; - char ch; - int i; - int flag = FALSE; + char *p = str; + char ch; + int i; + int flag = FALSE; *p++ = '0'; *p++ = 'x'; - if(num == 0){ + if (num == 0) + { *p++ = '0'; } - else{ - for(i=28;i>=0;i-=4){ + else + { + for (i = 28; i >= 0; i -= 4) + { ch = (num >> i) & 0xF; - if(flag || (ch > 0)){ + if (flag || (ch > 0)) + { flag = TRUE; ch += '0'; - if(ch > '9'){ + if (ch > '9') + { ch += 7; } *p++ = ch; @@ -49,27 +53,20 @@ return str; } - /*======================================================================* - disp_int + delay *======================================================================*/ - void disp_int(int input) -{ - char output[16]; - itoa(output, input); - disp_str(output); -} - -/*======================================================================* - delay - *======================================================================*/ - void delay(int time) +void delay(int time) { int i, j, k; - for(k=0;k