Skip to content

Commit

Permalink
实验7:实验6部分重构完成,已添加ESC功能;修复版本号和编译日期
Browse files Browse the repository at this point in the history
  • Loading branch information
Jed-Z committed May 29, 2019
1 parent abbaf44 commit 699a887
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 128 deletions.
7 changes: 4 additions & 3 deletions 项目7_进程控制与通信/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "stringio.h"
#include "process.h"
#define BUFLEN 16
#define OS_VERSION "1.4"
#define OS_VERSION "1.5"
#define OS_BUILDDATE "2019-05-29"

extern void clearScreen();
extern void powerOff();
Expand Down Expand Up @@ -37,7 +38,7 @@ void Delay()
{
int i = 0;
int j = 0;
for( i=0;i<100000;i++ )
for( i=0;i<10000;i++ )
for( j=0;j<10000;j++ )
{
j++;
Expand All @@ -52,7 +53,7 @@ void startUp() {
clearScreen();
const char* title = "JedOS v" OS_VERSION;
const char* subtitle = "Zhang Yixin, 17341203";
const char* date = "2019-05-04";
const char* date = OS_BUILDDATE;
const char* hint = "System has been loaded successfully. Press ENTER to start shell.";
printInPos(title, strlen(title), 5, 35);
printInPos(subtitle, strlen(subtitle), 6, 29);
Expand Down
117 changes: 66 additions & 51 deletions 项目7_进程控制与通信/src/multiprocess.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BITS 16
[extern getPcbTable]
[extern pcbSchedule]

Timer: ; 08h号时钟中断处理程序
Timer: ; 08h号时钟中断处理程序
cmp word[cs:timer_flag], 0
je QuitTimer
push ss
Expand All @@ -31,15 +31,30 @@ Timer: ; 08h号时钟中断处理程序
push ax

mov ax, cs
mov ds, ax ; ds=cs,因为函数中可能要用到ds
mov es, ax ; es=ax,原因同上。注意此时尚未发生栈切换

call pcbSave ; 将寄存器的值保存在PCB中
add sp, 16*2 ; 丢弃参数

call dword pcbSchedule ; 进程调度

PcbRestart: ; 不是函数
mov ds, ax ; ds=cs,因为函数中可能要用到ds
mov es, ax ; es=ax,原因同上。注意此时尚未发生栈切换

call pcbSave ; 将寄存器的值保存在PCB中
add sp, 16*2 ; 丢弃参数

CheckEscKey:
mov ah, 01h ; 功能号:查询键盘缓冲区但不等待
int 16h
jz ContinucSchedule ; 无键盘按下,继续调度
mov ah, 0 ; 功能号:查询键盘输入
int 16h
cmp al, 27 ; 是否按下ESC
jne ContinucSchedule ; 若按下的不是ESC,继续调度

mov word[cs:current_process_id], 0
mov word[cs:timer_flag], 0 ; 禁止时钟中断处理多进程
call resetAllPcbExceptZero ; 清理PCB
jmp PcbRestart ; 通过恢复返回内核

ContinucSchedule:
call dword pcbSchedule ; 进程调度

PcbRestart: ; 不是函数
call dword getCurrentPcb
mov si, ax
mov ax, [cs:si+0]
Expand All @@ -54,13 +69,13 @@ PcbRestart: ; 不是函数
mov fs, [cs:si+20]
mov gs, [cs:si+22]
mov ss, [cs:si+24]
add sp, 11*2 ; 恢复正确的sp
push word[cs:si+30] ; 新进程flags
push word[cs:si+28] ; 新进程cs
push word[cs:si+26] ; 新进程ip
add sp, 11*2 ; 恢复正确的sp
push word[cs:si+30] ; 新进程flags
push word[cs:si+28] ; 新进程cs
push word[cs:si+26] ; 新进程ip

push word[cs:si+12]
pop si ; 恢复si
pop si ; 恢复si

QuitTimer:
push ax
Expand All @@ -73,10 +88,10 @@ QuitTimer:
timer_flag dw 0
current_process_id dw 0

pcbSave: ; 函数:现场保护
pcbSave: ; 函数:现场保护
pusha
mov bp, sp
add bp, 16+2 ; 参数首地址
add bp, 16+2 ; 参数首地址

call dword getCurrentPcb
mov di, ax
Expand Down Expand Up @@ -119,62 +134,62 @@ pcbSave: ; 函数:现场保护
ret


loadProcessMem: ; 函数:将某个用户程序加载入内存并初始化其PCB
loadProcessMem: ; 函数:将某个用户程序加载入内存并初始化其PCB
pusha
mov bp, sp
add bp, 16+4 ; 参数地址
add bp, 16+4 ; 参数地址
LOAD_TO_MEM [bp+12], [bp], [bp+4], [bp+8], [bp+16], [bp+20]

call dword getPcbTable
mov si, ax
mov ax, 34
mul word[bp+24] ; progid_to_run
mul word[bp+24] ; progid_to_run
add si, ax

mov ax, [bp+24] ; ax=progid_to_run
mov byte[cs:si+32], al ; id
mov ax, [bp+16] ; ax=用户程序的段值
mov word[cs:si+8], 0FE00h ; sp
mov word[cs:si+16], ax ; ds
mov word[cs:si+18], ax ; es
mov word[cs:si+20], ax ; fs
mov word[cs:si+24], ax ; ss
mov word[cs:si+28], ax ; cs
mov word[cs:si+30], 512 ; flags
mov byte[cs:si+33], 1 ; state设其状态为就绪态
mov ax, [bp+24] ; ax=progid_to_run
mov byte[cs:si+32], al ; id
mov ax, [bp+16] ; ax=用户程序的段值
mov word[cs:si+8], 0FE00h ; sp
mov word[cs:si+16], ax ; ds
mov word[cs:si+18], ax ; es
mov word[cs:si+20], ax ; fs
mov word[cs:si+24], ax ; ss
mov word[cs:si+28], ax ; cs
mov word[cs:si+30], 512 ; flags
mov byte[cs:si+33], 1 ; state设其状态为就绪态

popa
retf

resetAllPcbExceptZero:
push cx
push si
mov cx, 7 ; 共8个PCB
mov cx, 7 ; 共8个PCB

call dword getPcbTable
mov si, ax
add si, 34

loop1:
mov word[cs:si+0], 0 ; ax
mov word[cs:si+2], 0 ; cx
mov word[cs:si+4], 0 ; dx
mov word[cs:si+6], 0 ; bx
mov word[cs:si+8], 0FE00h ; sp
mov word[cs:si+10], 0 ; bp
mov word[cs:si+12], 0 ; si
mov word[cs:si+14], 0 ; di
mov word[cs:si+16], 0 ; ds
mov word[cs:si+18], 0 ; es
mov word[cs:si+20], 0 ; fs
mov word[cs:si+22], 0B800h ; gs
mov word[cs:si+24], 0 ; ss
mov word[cs:si+26], 0 ; ip
mov word[cs:si+28], 0 ; cs
mov word[cs:si+30], 512 ; flags
mov byte[cs:si+32], 0 ; id
mov byte[cs:si+33], 0 ; state=新建态
add si, 34 ; si指向下一个PCB
mov word[cs:si+0], 0 ; ax
mov word[cs:si+2], 0 ; cx
mov word[cs:si+4], 0 ; dx
mov word[cs:si+6], 0 ; bx
mov word[cs:si+8], 0FE00h ; sp
mov word[cs:si+10], 0 ; bp
mov word[cs:si+12], 0 ; si
mov word[cs:si+14], 0 ; di
mov word[cs:si+16], 0 ; ds
mov word[cs:si+18], 0 ; es
mov word[cs:si+20], 0 ; fs
mov word[cs:si+22], 0B800h ; gs
mov word[cs:si+24], 0 ; ss
mov word[cs:si+26], 0 ; ip
mov word[cs:si+28], 0 ; cs
mov word[cs:si+30], 512 ; flags
mov byte[cs:si+32], 0 ; id
mov byte[cs:si+33], 0 ; state=新建态
add si, 34 ; si指向下一个PCB
loop loop1

pop si
Expand Down
11 changes: 1 addition & 10 deletions 项目7_进程控制与通信/src/usrprog/stone_bottomleft.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ start:
push ds
mov ax, 0
mov es, ax
; MOVE_INT_VECTOR 09h, 39h
; WRITE_INT_VECTOR 09h, IntOuch
call ClearScreen ; 清屏
mov ax,cs
mov es,ax ; ES = CS
Expand All @@ -35,8 +33,6 @@ start:
mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区
mov byte[char],'X'

; PRINT_IN_POS hint1, hint1len, 16, 30

initialize: ; 多次调用用户程序时,可保证初始值是相同的
mov word[x], originpos_x
mov word[y], originpos_y
Expand Down Expand Up @@ -220,9 +216,4 @@ DataArea:
y dw originpos_y

curcolor db 80h ; 保存当前字符颜色属性,用于myinfo
curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符

; hint1 db 'This is user program 3. Press ESC to exit.'
; hint1len equ ($-hint1)

; %include "interrupt/intouch.asm"
curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符
11 changes: 1 addition & 10 deletions 项目7_进程控制与通信/src/usrprog/stone_bottomright.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ start:
push ds
mov ax, 0
mov es, ax
; MOVE_INT_VECTOR 09h, 39h
; WRITE_INT_VECTOR 09h, IntOuch
call ClearScreen ; 清屏
mov ax,cs
mov es,ax ; ES = CS
Expand All @@ -35,8 +33,6 @@ start:
mov gs,ax ; GS = B800h,指向文本模式的显示缓冲区
mov byte[char],'X'

; PRINT_IN_POS hint1, hint1len, 16, 30

initialize: ; 多次调用用户程序时,可保证初始值是相同的
mov word[x], originpos_x
mov word[y], originpos_y
Expand Down Expand Up @@ -220,9 +216,4 @@ DataArea:
y dw originpos_y

curcolor db 80h ; 保存当前字符颜色属性,用于myinfo
curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符

; hint1 db 'This is user program 4. Press ESC to exit.'
; hint1len equ ($-hint1)

; %include "interrupt/intouch.asm"
curcolor2 db 01h ; 保存当前字符颜色属性,用于移动的字符
Loading

0 comments on commit 699a887

Please sign in to comment.