delete disp_*

This commit is contained in:
xiaoxiao 2023-01-02 13:06:27 +08:00
parent f70a22b8c2
commit c40f00c80e
14 changed files with 362 additions and 566 deletions

View File

@ -9,8 +9,8 @@
#define _ORANGES_CONST_H_ #define _ORANGES_CONST_H_
/*最大整数定义*/ /*最大整数定义*/
#define MAX_UNSIGNED_INT 0xFFFFFFFF //最大的无符号整形 #define MAX_UNSIGNED_INT 0xFFFFFFFF // 最大的无符号整形
#define MAX_INT 0x7FFFFFFF //最大的整形数 #define MAX_INT 0x7FFFFFFF // 最大的整形数
/* Color */ /* Color */
/* /*
@ -18,7 +18,7 @@
* MAKE_COLOR(BLACK, RED) | BRIGHT * MAKE_COLOR(BLACK, RED) | BRIGHT
* MAKE_COLOR(BLACK, RED) | BRIGHT | FLASH * MAKE_COLOR(BLACK, RED) | BRIGHT | FLASH
*/ */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define BLACK 0x0 /* 0000 */ #define BLACK 0x0 /* 0000 */
#define BLUE 0x1 /* 0001 */ #define BLUE 0x1 /* 0001 */
#define GREEN 0x2 /* 0010 */ #define GREEN 0x2 /* 0010 */
@ -29,7 +29,7 @@
#define WHITE 0x7 /* 0111 actually its light grey, white = bright light grey*/ #define WHITE 0x7 /* 0111 actually its light grey, white = bright light grey*/
#define FLASH 0x80 /* 1000 0000 */ #define FLASH 0x80 /* 1000 0000 */
#define BRIGHT 0x08 /* 0000 1000 */ #define BRIGHT 0x08 /* 0000 1000 */
#define MAKE_COLOR(x,y) ((x<<4) | y) /* MAKE_COLOR(Background,Foreground) */ #define MAKE_COLOR(x, y) ((x << 4) | y) /* MAKE_COLOR(Background,Foreground) */
/* Boolean */ /* Boolean */
#define TRUE 1 #define TRUE 1
@ -57,10 +57,10 @@
/* 8253/8254 PIT (Programmable Interval Timer) */ /* 8253/8254 PIT (Programmable Interval Timer) */
#define TIMER0 0x40 /* I/O port for timer channel 0 */ #define TIMER0 0x40 /* I/O port for timer channel 0 */
#define TIMER_MODE 0x43 /* I/O port for timer mode control */ #define TIMER_MODE 0x43 /* I/O port for timer mode control */
#define RATE_GENERATOR 0x34 /* 00-11-010-0 : #define RATE_GENERATOR 0x34 /* 00-11-010-0 : \
* Counter0 - LSB then MSB - rate generator - binary * Counter0 - LSB then MSB - rate generator - binary \
*/ */
#define TIMER_FREQ 1193182L/* clock frequency for timer in PC and AT */ #define TIMER_FREQ 1193182L /* clock frequency for timer in PC and AT */
#define HZ 100 /* clock freq (software settable on IBM-PC) */ #define HZ 100 /* clock freq (software settable on IBM-PC) */
/* Hardware interrupts */ /* Hardware interrupts */
@ -75,57 +75,57 @@
#define FLOPPY_IRQ 6 /* floppy disk */ #define FLOPPY_IRQ 6 /* floppy disk */
#define PRINTER_IRQ 7 #define PRINTER_IRQ 7
#define AT_WINI_IRQ 14 /* at winchester */ #define AT_WINI_IRQ 14 /* at winchester */
#define MOUSE_IRQ 12 //added by mingxuan 2019-5-19 #define MOUSE_IRQ 12 // added by mingxuan 2019-5-19
/* system call */ /* system call */
//#define NR_SYS_CALL 23 //last modified by xw, 18/6/19 // #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 26 // modified by mingxuan 2019-5-17
/* TTY */ /* TTY */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define NR_CONSOLES 3 /* consoles */ #define NR_CONSOLES 3 /* consoles */
/*页表相关*/ /*页表相关*/
#define PageTblNumAddr 0x500 //页表数量放在这个位置,必须与load.inc中一致 add by visual 2016.5.11 #define PageTblNumAddr 0x500 // 页表数量放在这个位置,必须与load.inc中一致 add by visual 2016.5.11
#define KernelPageTblAddr 0x200000 //内核页表物理地址必须与load.inc中一致 add by visual 2016.5.17 #define KernelPageTblAddr 0x200000 // 内核页表物理地址必须与load.inc中一致 add by visual 2016.5.17
/*线性地址描述*/ //edit by visual 2016.5.25 /*线性地址描述*/ // edit by visual 2016.5.25
#define KernelSize 0x800000 //内核的大小//add by visual 2016.5.10 #define KernelSize 0x800000 // 内核的大小//add by visual 2016.5.10
#define K_PHY2LIN(x) ((x)+0xC0000000) //内核中物理地址转线性地址 //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 K_LIN2PHY(x) ((x)-0xC0000000) // added by xw, 18/8/27
#define num_4B 0x4 //4B大小 #define num_4B 0x4 // 4B大小
#define num_1K 0x400 //1k大小 #define num_1K 0x400 // 1k大小
#define num_4K 0x1000 //4k大小 #define num_4K 0x1000 // 4k大小
#define num_4M 0x400000 //4M大小 #define num_4M 0x400000 // 4M大小
#define TextLinBase ((u32)0x0) //进程代码的起始地址这是参考值具体以elf描述为准 #define TextLinBase ((u32)0x0) // 进程代码的起始地址这是参考值具体以elf描述为准
#define TextLinLimitMAX (TextLinBase+0x20000000) //大小512M这是参考值具体以elf描述为准 #define TextLinLimitMAX (TextLinBase + 0x20000000) // 大小512M这是参考值具体以elf描述为准
#define DataLinBase TextLinLimitMAX //进程数据的起始地址这是参考值具体以elf描述为准 #define DataLinBase TextLinLimitMAX // 进程数据的起始地址这是参考值具体以elf描述为准
#define DataLinLimitMAX (DataLinBase+0x20000000) //大小512M这是参考值具体以elf描述为准但是代码和数据长度总和不能超过这个值 #define DataLinLimitMAX (DataLinBase + 0x20000000) // 大小512M这是参考值具体以elf描述为准但是代码和数据长度总和不能超过这个值
#define VpageLinBase DataLinLimitMAX //保留内存起始地址 #define VpageLinBase DataLinLimitMAX // 保留内存起始地址
#define VpageLinLimitMAX (VpageLinBase+0x8000000-num_4K) //大小128M-4k #define VpageLinLimitMAX (VpageLinBase + 0x8000000 - num_4K) // 大小128M-4k
#define SharePageBase VpageLinLimitMAX //共享页线性地址执行fork\pthread的时候用,共享页必须4K对齐 #define SharePageBase VpageLinLimitMAX // 共享页线性地址执行fork\pthread的时候用,共享页必须4K对齐
#define SharePageLimit (SharePageBase+num_4K) //大小4k #define SharePageLimit (SharePageBase + num_4K) // 大小4k
#define HeapLinBase SharePageLimit //堆的起始地址 #define HeapLinBase SharePageLimit // 堆的起始地址
#define HeapLinLimitMAX (HeapLinBase+0x40000000) //大小1G #define HeapLinLimitMAX (HeapLinBase + 0x40000000) // 大小1G
#define StackLinLimitMAX HeapLinLimitMAX //栈的大小: 1G-128M-4K注意栈的基址和界限方向 #define StackLinLimitMAX HeapLinLimitMAX // 栈的大小: 1G-128M-4K注意栈的基址和界限方向
#define StackLinBase (ArgLinBase-num_4B) //=(StackLinLimitMAX+1G-128M-4K-4B)栈的起始地址,放在参数位置之前(注意堆栈的增长方向) #define StackLinBase (ArgLinBase - num_4B) //=(StackLinLimitMAX+1G-128M-4K-4B)栈的起始地址,放在参数位置之前(注意堆栈的增长方向)
#define ArgLinBase (KernelLinBase-0x1000) //参数存放位置起始地址放在3G前暂时还没没用到 #define ArgLinBase (KernelLinBase - 0x1000) // 参数存放位置起始地址放在3G前暂时还没没用到
#define ArgLinLimitMAX KernelLinBase //=(ArgLinBase+0x1000)大小4K。 #define ArgLinLimitMAX KernelLinBase //=(ArgLinBase+0x1000)大小4K。
#define KernelLinBase 0xC0000000 //内核线性起始地址(有0x30400的偏移) #define KernelLinBase 0xC0000000 // 内核线性起始地址(有0x30400的偏移)
#define KernelLinLimitMAX (KernelLinBase+0x40000000) //大小1G #define KernelLinLimitMAX (KernelLinBase + 0x40000000) // 大小1G
/***************目前线性地址布局***************************** edit by visual 2016.5.25 /***************目前线性地址布局***************************** edit by visual 2016.5.25
* 0 ~ 512M ,512M * 0 ~ 512M ,512M
* 512M ~ 1G512M * 512M ~ 1G512M
* 1G ~ 1G+128M128M, * 1G ~ 1G+128M128M,
* 1G+128M ~ 2G+128M1G * 1G+128M ~ 2G+128M1G
* 2G+128M ~ 3G-4K, 1G-128M-4K * 2G+128M ~ 3G-4K, 1G-128M-4K
* 3G-4K~3G4K * 3G-4K~3G4K
* 3G~4G1G * 3G~4G1G
***********************************************************/ ***********************************************************/
//#define ShareTblLinAddr (KernelLinLimitMAX-0x1000) //公共临时共享页,放在内核最后一个页表的最后一项上 // #define ShareTblLinAddr (KernelLinLimitMAX-0x1000) //公共临时共享页,放在内核最后一个页表的最后一项上
/*分页机制常量的定义,必须与load.inc中一致*/ //add by visual 2016.4.5 /*分页机制常量的定义,必须与load.inc中一致*/ // add by visual 2016.4.5
#define PG_P 1 // 页存在属性位 #define PG_P 1 // 页存在属性位
#define PG_RWR 0 // R/W 属性位值, 读/执行 #define PG_RWR 0 // R/W 属性位值, 读/执行
#define PG_RWW 2 // R/W 属性位值, 读/写/执行 #define PG_RWW 2 // R/W 属性位值, 读/写/执行
@ -135,24 +135,24 @@
/* AT keyboard */ /* AT keyboard */
/* 8042 ports */ /* 8042 ports */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define KB_DATA 0x60 /* I/O port for keyboard data #define KB_DATA 0x60 /* I/O port for keyboard data \
* Read : Read Output Buffer * Read : Read Output Buffer \
* Write: Write Input Buffer * Write: Write Input Buffer \
* (8042 Data & 8048 Command) * (8042 Data & 8048 Command) \
*/ */
#define KB_CMD 0x64 /* I/O port for keyboard command #define KB_CMD 0x64 /* I/O port for keyboard command \
* Read : Read Status Register * Read : Read Status Register \
* Write: Write Input Buffer * Write: Write Input Buffer \
* (8042 Command) * (8042 Command) \
*/ */
#define KB_STA 0x64 #define KB_STA 0x64
#define KEYSTA_SEND_NOTREADY 0x02 #define KEYSTA_SEND_NOTREADY 0x02
#define KBSTATUS_IBF 0x02 #define KBSTATUS_IBF 0x02
#define KBSTATUS_OBF 0x01 #define KBSTATUS_OBF 0x01
#define wait_KB_write() while(in_byte(KB_STA) & KBSTATUS_IBF) #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_read() while (in_byte(KB_STA) & KBSTATUS_OBF)
#define KEYCMD_WRITE_MODE 0x60 #define KEYCMD_WRITE_MODE 0x60
#define KBC_MODE 0x47 #define KBC_MODE 0x47
@ -165,7 +165,7 @@
#define KB_ACK 0xFA #define KB_ACK 0xFA
/* VGA */ /* VGA */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */ #define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */
#define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data 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_H 0xC /* reg index of video mem start addr (MSB) */
@ -180,8 +180,8 @@
#define STD_ERR 2 #define STD_ERR 2
/* max() & min() */ /* max() & min() */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define max(a,b) ((a) > (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? -(a) : (a)) #define abs(a) ((a) < 0 ? -(a) : (a))
#endif /* _ORANGES_CONST_H_ */ #endif /* _ORANGES_CONST_H_ */

View File

@ -5,13 +5,7 @@
Forrest Yu, 2005 Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* klib.asm */ // added by zcr
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 disable_irq(int irq);
void enable_irq(int irq); void enable_irq(int irq);
void init_8259A(); void init_8259A();
@ -25,39 +19,39 @@ u32 seg2phys(u16 seg);
void delay(int time); void delay(int time);
/* kernel.asm */ /* kernel.asm */
u32 read_cr2(); //add by visual 2016.5.9 u32 read_cr2(); // add by visual 2016.5.9
void refresh_page_cache(); //add by visual 2016.5.12 void refresh_page_cache(); // add by visual 2016.5.12
//void restart_int(); // void restart_int();
//void save_context(); // void save_context();
void restart_initial(); //added by xw, 18/4/18 void restart_initial(); // added by xw, 18/4/18
void restart_restore(); //added by xw, 18/4/20 void restart_restore(); // added by xw, 18/4/20
void sched(); //added by xw, 18/4/18 void sched(); // added by xw, 18/4/18
void halt(); //added by xw, 18/6/11 void halt(); // added by xw, 18/6/11
u32 get_arg(void *uesp, int order); //added by xw, 18/6/18 u32 get_arg(void *uesp, int order); // added by xw, 18/6/18
/* ktest.c */ /* ktest.c */
void initial(); void initial();
/* keyboard.c */ /* keyboard.c */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
void init_kb(); void init_kb();
void keyboard_read(); void keyboard_read();
/* tty.c */ /* tty.c */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
void in_process(TTY* p_tty,u32 key); void in_process(TTY *p_tty, u32 key);
void task_tty(); void task_tty();
void tty_write(NTTY* tty, char* buf, int len); void tty_write(NTTY *tty, char *buf, int len);
int tty_read(NTTY* tty, char* buf, int len); int tty_read(NTTY *tty, char *buf, int len);
void init_tty_main(); void init_tty_main();
NTTY* get_tty(const int nr_tty); NTTY *get_tty(const int nr_tty);
/* printf.c */ /* printf.c */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
int printf(const char *fmt, ...); int printf(const char *fmt, ...);
/* vsprintf.c */ /* vsprintf.c */
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
int vsprintf(char *buf, const char *fmt, va_list args); int vsprintf(char *buf, const char *fmt, va_list args);
/* i8259.c */ /* i8259.c */
@ -68,76 +62,71 @@ void spurious_irq(int irq);
void clock_handler(int irq); void clock_handler(int irq);
/*************************************************************** /***************************************************************
* *
****************************************************************/ ****************************************************************/
/* syscall.asm */ /* syscall.asm */
void sys_call(); /* int_handler */ void sys_call(); /* int_handler */
int get_ticks(); int get_ticks();
int get_pid(); //add by visual 2016.4.6 int get_pid(); // add by visual 2016.4.6
void* kmalloc(int size); //edit by visual 2016.5.9 void *kmalloc(int size); // edit by visual 2016.5.9
void* kmalloc_4k(); //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(int size); // edit by visual 2016.5.9
void* malloc_4k(); //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(void *arg); // edit by visual 2016.5.9
int free_4k(void* AdddrLin); //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 fork(); // add by visual 2016.4.8
int pthread(void *arg); //add by visual 2016.4.11 int pthread(void *arg); // add by visual 2016.4.11
void udisp_int(int arg); //add by visual 2016.5.16 u32 exec(char *path); // add by visual 2016.5.16
void udisp_str(char* arg); //add by visual 2016.5.16 void yield(); // added by xw, 18/4/19
u32 exec(char* path); //add by visual 2016.5.16 void sleep(int n); // added by xw, 18/4/19
void yield(); //added by xw, 18/4/19
void sleep(int n); //added by xw, 18/4/19
void print_E(); void print_E();
void print_F(); void print_F();
/* syscallc.c */ //edit by visual 2016.4.6 /* syscallc.c */ // edit by visual 2016.4.6
int sys_get_ticks(); /* sys_call */ int sys_get_ticks(); /* sys_call */
int sys_get_pid(); //add by visual 2016.4.6 int sys_get_pid(); // add by visual 2016.4.6
void* sys_kmalloc(int size); //edit by visual 2016.5.9 void *sys_kmalloc(int size); // edit by visual 2016.5.9
void* sys_kmalloc_4k(); //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(int size); // edit by visual 2016.5.9
void* sys_malloc_4k(); //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(void *arg); // edit by visual 2016.5.9
int sys_free_4k(void* AdddrLin); //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 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
/* proc.c */ /* proc.c */
PROCESS* alloc_PCB(); PROCESS *alloc_PCB();
void free_PCB(PROCESS *p); void free_PCB(PROCESS *p);
void sys_yield(); void sys_yield();
void sys_sleep(int n); void sys_sleep(int n);
void sys_wakeup(void *channel); void sys_wakeup(void *channel);
int ldt_seg_linear(PROCESS *p, int idx); int ldt_seg_linear(PROCESS *p, int idx);
void* va2la(int pid, void* va); void *va2la(int pid, void *va);
/* testfunc.c */ /* testfunc.c */
void sys_print_E(); void sys_print_E();
void sys_print_F(); void sys_print_F();
/*exec.c*/ /*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*/ /*fork.c*/
int sys_fork(); //add by visual 2016.5.25 int sys_fork(); // add by visual 2016.5.25
/*************************************************************** /***************************************************************
* *
****************************************************************/ ****************************************************************/
/*pagepte.c*/ /*pagepte.c*/
u32 init_page_pte(u32 pid); //edit 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 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_pde_index(u32 AddrLin); // add by visual 2016.4.28
u32 get_pte_index(u32 AddrLin); u32 get_pte_index(u32 AddrLin);
u32 get_pde_phy_addr(u32 pid); u32 get_pde_phy_addr(u32 pid);
u32 get_pte_phy_addr(u32 pid,u32 AddrLin); u32 get_pte_phy_addr(u32 pid, u32 AddrLin);
u32 get_page_phy_addr(u32 pid,u32 AddrLin);//线性地址 u32 get_page_phy_addr(u32 pid, u32 AddrLin); // 线性地址
u32 pte_exist(u32 PageTblAddrPhy,u32 AddrLin); u32 pte_exist(u32 PageTblAddrPhy, u32 AddrLin);
u32 phy_exist(u32 PageTblPhyAddr,u32 AddrLin); u32 phy_exist(u32 PageTblPhyAddr, u32 AddrLin);
void write_page_pde(u32 PageDirPhyAddr,u32 AddrLin,u32 TblPhyAddr,u32 Attribute); void write_page_pde(u32 PageDirPhyAddr, u32 AddrLin, u32 TblPhyAddr, u32 Attribute);
void write_page_pte( u32 TblPhyAddr,u32 AddrLin,u32 PhyAddr,u32 Attribute); void write_page_pte(u32 TblPhyAddr, u32 AddrLin, u32 PhyAddr, u32 Attribute);
u32 vmalloc(u32 size); 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 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 void clear_kernel_pagepte_low(); // add by visual 2016.5.12

View File

@ -1,28 +1,26 @@
/******************************************** /********************************************
* add by visual 2016.5.16 * add by visual 2016.5.16
*************************************************/ *************************************************/
#include "const.h" //added by mingxuan 2019-5-19 #include "const.h" //added by mingxuan 2019-5-19
#include "type.h" //added by mingxuan 2019-5-19 #include "type.h" //added by mingxuan 2019-5-19
#include "stdarg.h" #include "stdarg.h"
#ifndef _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 #define _STDIO_H_ // added by mingxuan 2019-5-19
/*syscall.asm*/ /*syscall.asm*/
int get_ticks(); int get_ticks();
int get_pid(); int get_pid();
void* kmalloc(int size); void *kmalloc(int size);
void* kmalloc_4k(); void *kmalloc_4k();
void* malloc(int size); void *malloc(int size);
void* malloc_4k(); void *malloc_4k();
int free(void *arg); int free(void *arg);
int free_4k(void* AdddrLin); int free_4k(void *AdddrLin);
int fork(); int fork();
int pthread(void *arg); int pthread(void *arg);
void udisp_int(int arg);
void udisp_str(char* arg);
//added by xw // added by xw
/* file system */ /* file system */
#define MAX_FILENAME_LEN 12 #define MAX_FILENAME_LEN 12
#define MAX_PATH 128 #define MAX_PATH 128
@ -32,32 +30,32 @@ void udisp_str(char* arg);
#define SEEK_CUR 2 #define SEEK_CUR 2
#define SEEK_END 3 #define SEEK_END 3
int open(const char *pathname, int flags); //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 close(int fd); // added by xw, 18/6/19
int read(int fd, void *buf, int count); //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 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 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 unlink(const char *pathname); // added by xw, 18/6/19
//~xw //~xw
/*string.asm*/ /*string.asm*/
long strtol(const char *cp,char **endp,unsigned int base); long strtol(const char *cp, char **endp, unsigned int base);
/*printf.c*/ /*printf.c*/
//added by mingxuan 2019-5-19 // added by mingxuan 2019-5-19
#define EOF -1 #define EOF -1
// #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 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_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
// #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) // #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
// #define va_end(ap) ( ap = (va_list)0 ) // #define va_end(ap) ( ap = (va_list)0 )
#define isspace(s) (s==' ') #define isspace(s) (s == ' ')
#define TOLOWER(x) ((x) | 0x20) #define TOLOWER(x) ((x) | 0x20)
#define isxdigit(c) (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F')) #define isxdigit(c) (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F'))
#define isdigit(c) ('0' <= (c) && (c) <= '9') #define isdigit(c) ('0' <= (c) && (c) <= '9')
void printfmt(void (*putch)(int, void*), void *putdat, 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); 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 vsnprintf(char *buf, int n, const char *fmt, va_list ap);
int snprintf(char *buf, int n, const char *fmt, ...); int snprintf(char *buf, int n, const char *fmt, ...);
@ -68,7 +66,7 @@ int vkprintf(const char *fmt, va_list ap);
int kprintf(const char *fmt, ...); int kprintf(const char *fmt, ...);
// int scanf(char *str, ...); // int scanf(char *str, ...);
char getchar(); //added by mingxuan 2019-5-23 char getchar(); // added by mingxuan 2019-5-23
char* gets(char *str); //added by mingxuan 2019-5-23 char *gets(char *str); // added by mingxuan 2019-5-23
#endif //added by mingxuan 2019-5-19 #endif // added by mingxuan 2019-5-19

View File

@ -33,7 +33,6 @@ KERN_SRCFILES :=kernel/kernel.asm \
kernel/serialport.c \ kernel/serialport.c \
kernel/vga.c \ kernel/vga.c \
lib/klib.c \ lib/klib.c \
lib/kliba.asm \
KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES)) KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))

View File

@ -97,7 +97,6 @@ void out_char(CONSOLE *con, char ch)
//*(pch - 2) = ' '; //*(pch - 2) = ' ';
//*(pch - 1) = DEFAULT_CHAR_COLOR; //*(pch - 1) = DEFAULT_CHAR_COLOR;
disp_pos = con->cursor * 2; disp_pos = con->cursor * 2;
// write_char(' ');
write_char_c(disp_pos, ' '); write_char_c(disp_pos, ' ');
} }
break; break;
@ -105,7 +104,6 @@ void out_char(CONSOLE *con, char ch)
//*pch++ = ch; //*pch++ = ch;
//*pch++ = DEFAULT_CHAR_COLOR; //*pch++ = DEFAULT_CHAR_COLOR;
disp_pos = con->cursor * 2; disp_pos = con->cursor * 2;
// write_char(ch);
write_char_c(disp_pos, ch); write_char_c(disp_pos, ch);
con->cursor++; con->cursor++;

View File

@ -61,19 +61,17 @@ system_call sys_call_table[NR_SYS_CALL] = {
sys_free_4k, // 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_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_exec, // add by visual 2016.5.16
sys_yield, // added by xw sys_yield, // added by xw
sys_sleep, // added by xw //15th sys_sleep, // added by xw //13th
sys_print_E, // added by xw sys_print_E, // added by xw
sys_print_F, // added by xw sys_print_F, // added by xw
sys_open, // added by xw, 18/6/18 sys_open, // added by xw, 18/6/18
sys_close, // added by xw, 18/6/18 sys_close, // added by xw, 18/6/18
sys_read, // added by xw, 18/6/18 //20th sys_read, // added by xw, 18/6/18 //18th
sys_write, // added by xw, 18/6/18 sys_write, // added by xw, 18/6/18
sys_lseek, // added by xw, 18/6/18 sys_lseek, // added by xw, 18/6/18
sys_unlink, // added by xw, 18/6/19 //23th sys_unlink, // added by xw, 18/6/19 //21th
sys_create, // added by mingxuan 2019-5-17 sys_create, // added by mingxuan 2019-5-17
sys_delete, // added by mingxuan 2019-5-17 sys_delete, // added by mingxuan 2019-5-17
sys_opendir, // added by mingxuan 2019-5-17 sys_opendir, // added by mingxuan 2019-5-17

View File

@ -14,12 +14,10 @@ extern kernel_main
extern exception_handler extern exception_handler
extern spurious_irq extern spurious_irq
extern clock_handler extern clock_handler
extern disp_str
extern delay extern delay
extern irq_table extern irq_table
extern page_fault_handler extern page_fault_handler
extern divide_error_handler ;added by xw, 18/12/22 extern divide_error_handler ;added by xw, 18/12/22
extern disp_int
extern schedule extern schedule
extern switch_pde extern switch_pde

View File

@ -132,8 +132,7 @@ void initial()
do_vclose(stdout); do_vclose(stdout);
do_vclose(stderr); do_vclose(stderr);
// exec("orange/shell_1.bin"); exec("orange/shell_1.bin");
exec("orange/test.bin");
while (1) while (1)
; ;

View File

@ -37,12 +37,6 @@ int kernel_main()
init_serial(); init_serial();
int error; int error;
// disp_pos = 0;
// for (int i = 0; i < 25; i++) {
// for (int j = 0; j < 80; j++) {
// disp_str(" ");
// }
// }
disp_pos = 0; disp_pos = 0;
// kprintf("-----Kernel Initialization Begins-----\n"); // kprintf("-----Kernel Initialization Begins-----\n");

View File

@ -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_free_4k equ 7 ; //add by visual 2016.4.7
_NR_fork equ 8 ; //add by visual 2016.4.8 _NR_fork equ 8 ; //add by visual 2016.4.8
_NR_pthread equ 9 ; //add by visual 2016.4.11 _NR_pthread equ 9 ; //add by visual 2016.4.11
_NR_udisp_int equ 10 ; //add by visual 2016.5.16 _NR_exec equ 10 ; //add by visual 2016.5.16
_NR_udisp_str equ 11 ; //add by visual 2016.5.16 _NR_yield equ 11 ; //added by xw, 17/12
_NR_exec equ 12 ; //add by visual 2016.5.16 _NR_sleep equ 12 ; //added by xw, 17/12
_NR_yield equ 13 ; //added by xw, 17/12 _NR_print_E equ 13 ; //added by xw, 18/4/27
_NR_sleep equ 14 ; //added by xw, 17/12 _NR_print_F equ 14 ; //added by xw, 18/4/27
_NR_print_E equ 15 ; //added by xw, 18/4/27
_NR_print_F equ 16 ; //added by xw, 18/4/27
_NR_open equ 17 ; //added by xw, 18/6/18 _NR_open equ 15 ; //added by xw, 18/6/18
_NR_close equ 18 ; //added by xw, 18/6/18 _NR_close equ 16 ; //added by xw, 18/6/18
_NR_read equ 19 ; //added by xw, 18/6/18 _NR_read equ 17 ; //added by xw, 18/6/18
_NR_write equ 20 ; //added by xw, 18/6/18 _NR_write equ 18 ; //added by xw, 18/6/18
_NR_lseek equ 21 ; //added by xw, 18/6/18 _NR_lseek equ 19 ; //added by xw, 18/6/18
_NR_unlink equ 22 ; //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_create equ 21 ; //added by mingxuan 2019-5-17
_NR_delete equ 24 ; //added by mingxuan 2019-5-17 _NR_delete equ 22 ; //added by mingxuan 2019-5-17
_NR_opendir equ 25 ; //added by mingxuan 2019-5-17 _NR_opendir equ 22 ; //added by mingxuan 2019-5-17
_NR_createdir equ 26 ; //added by mingxuan 2019-5-17 _NR_createdir equ 24 ; //added by mingxuan 2019-5-17
_NR_deletedir equ 27 ; //added by mingxuan 2019-5-17 _NR_deletedir equ 25 ; //added by mingxuan 2019-5-17
INT_VECTOR_SYS_CALL equ 0x90 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 free_4k ; //add by visual 2016.4.7
global fork ; //add by visual 2016.4.8 global fork ; //add by visual 2016.4.8
global pthread ; //add by visual 2016.4.11 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 exec ; //add by visual 2016.5.16
global yield ; //added by xw global yield ; //added by xw
global sleep ; //added by xw global sleep ; //added by xw
@ -175,27 +171,6 @@ pthread:
pop ebx pop ebx
ret 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 ; exec //add by visual 2016.5.16

View File

@ -1,9 +1,9 @@
/********************************************************* /*********************************************************
* *
* *
* *
* *
**********************************************************/ **********************************************************/
#include "type.h" #include "type.h"
#include "const.h" #include "const.h"
@ -24,7 +24,6 @@ int sys_get_ticks()
return ticks; return ticks;
} }
/*======================================================================* /*======================================================================*
sys_get_pid add by visual 2016.4.6 sys_get_pid add by visual 2016.4.6
*======================================================================*/ *======================================================================*/
@ -36,101 +35,78 @@ 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) void *sys_kmalloc(int size)
{ //edit by visual 2015.5.9 { // edit by visual 2015.5.9
return (void*)(do_kmalloc(size)); 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() void *sys_kmalloc_4k()
{ {
return (void*)(do_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) void *sys_malloc(int size)
{ {
int vir_addr,AddrLin; int vir_addr, AddrLin;
vir_addr = vmalloc(size); vir_addr = vmalloc(size);
for( AddrLin=vir_addr; AddrLin<vir_addr+size ; AddrLin += num_4B )//一个字节一个字节处理 for (AddrLin = vir_addr; AddrLin < vir_addr + size; AddrLin += num_4B) // 一个字节一个字节处理
{ {
lin_mapping_phy(AddrLin,//线性地址 //add by visual 2016.5.9 lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9
MAX_UNSIGNED_INT,//物理地址 //edit by visual 2016.5.19 MAX_UNSIGNED_INT, // 物理地址 //edit by visual 2016.5.19
p_proc_current->task.pid,//进程pid //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, // 页目录的属性位
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() void *sys_malloc_4k()
{ {
int vir_addr,AddrLin; int vir_addr, AddrLin;
vir_addr = vmalloc(num_4K); vir_addr = vmalloc(num_4K);
for( AddrLin=vir_addr; AddrLin<vir_addr+num_4K ; AddrLin += num_4K )//一页一页处理(事实上只有一页,而且一定没有填写页表,页目录是否填写不确定) for (AddrLin = vir_addr; AddrLin < vir_addr + num_4K; AddrLin += num_4K) // 一页一页处理(事实上只有一页,而且一定没有填写页表,页目录是否填写不确定)
{ {
lin_mapping_phy( AddrLin,//线性地址 //add by visual 2016.5.9 lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9
MAX_UNSIGNED_INT,//物理地址 MAX_UNSIGNED_INT, // 物理地址
p_proc_current->task.pid,//进程pid //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, // 页目录的属性位
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) int sys_free(void *arg)
{ {
memarg = (struct memfree *)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 sys_free_4k(void *AddrLin)
{//线性地址可以不释放,但是页表映射关系必须清除! { // 线性地址可以不释放,但是页表映射关系必须清除!
int phy_addr; //add by visual 2016.5.9 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 phy_addr = get_page_phy_addr(p_proc_current->task.pid, (int)AddrLin); // 获取物理页的物理地址 //edit by visual 2016.5.19
lin_mapping_phy( (int)AddrLin,//线性地址 lin_mapping_phy((int)AddrLin, // 线性地址
phy_addr,//物理地址 phy_addr, // 物理地址
p_proc_current->task.pid,//进程pid //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, // 页目录的属性位
0 | PG_USU | PG_RWW);//页表的属性位 0 | PG_USU | PG_RWW); // 页表的属性位
return do_free_4k(phy_addr); 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 ;
}

View File

@ -13,13 +13,12 @@
#include "global.h" #include "global.h"
#include "proto.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 *p = str;
char ch; char ch;
int i; int i;
int flag = FALSE; int flag = FALSE;
@ -27,16 +26,21 @@
*p++ = '0'; *p++ = '0';
*p++ = 'x'; *p++ = 'x';
if(num == 0){ if (num == 0)
{
*p++ = '0'; *p++ = '0';
} }
else{ else
for(i=28;i>=0;i-=4){ {
for (i = 28; i >= 0; i -= 4)
{
ch = (num >> i) & 0xF; ch = (num >> i) & 0xF;
if(flag || (ch > 0)){ if (flag || (ch > 0))
{
flag = TRUE; flag = TRUE;
ch += '0'; ch += '0';
if(ch > '9'){ if (ch > '9')
{
ch += 7; ch += 7;
} }
*p++ = ch; *p++ = ch;
@ -49,27 +53,20 @@
return str; return str;
} }
/*======================================================================*
disp_int
*======================================================================*/
void disp_int(int input)
{
char output[16];
itoa(output, input);
disp_str(output);
}
/*======================================================================* /*======================================================================*
delay delay
*======================================================================*/ *======================================================================*/
void delay(int time) void delay(int time)
{ {
int i, j, k; int i, j, k;
for(k=0;k<time;k++){ for (k = 0; k < time; k++)
{
/*for(i=0;i<10000;i++){ for Virtual PC */ /*for(i=0;i<10000;i++){ for Virtual PC */
for(i=0;i<10;i++){/* for Bochs */ for (i = 0; i < 10; i++)
for(j=0;j<10000;j++){} { /* 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

@ -41,8 +41,7 @@ int main(int arg, char *argv[])
printf("%d", i); printf("%d", i);
printf("11111111111111111\n"); printf("11111111111111111\n");
} }
printf("\x1b[31;47mexec: path ERROR!\x1b[m"); printf("\x1b[31;47m555555555555\x1b[m");
printf("555555");
// Cursor Up // Cursor Up
// printf("\x1b[2A"); // printf("\x1b[2A");