加载中…
个人资料
liang
liang
  • 博客等级:
  • 博客积分:0
  • 博客访问:54,585
  • 关注人气:22
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
正文 字体大小:

临摹于渊的 Orange's , 之五, 源代码

(2013-04-26 19:23:44)

; long mode - 64bit code  
_64:
[bits 64]
 call Init8259A

        call setup_idt
        mov rbx,Idt64Ptr
        lidt [rbx] 
  
        sti  ; 打开中断
 jmp init ;$ ; 死循环,等待键盘信号

Init8259A:
 mov al, 011h
 out 020h, al ; 主8259, ICW1.
 call io_delay

 out 0A0h, al ; 从8259, ICW1.
 call io_delay

 mov al, 020h ; IRQ0 对应中断向量 0x20
 out 021h, al ; 主8259, ICW2.
 call io_delay

 mov al, 028h ; IRQ8 对应中断向量 0x28
 out 0A1h, al ; 从8259, ICW2.
 call io_delay

 mov al, 004h ; IR2 对应从8259
 out 021h, al ; 主8259, ICW3.
 call io_delay

 mov al, 002h ; 对应主8259的 IR2
 out 0A1h, al ; 从8259, ICW3.
 call io_delay

 mov al, 001h
 out 021h, al ; 主8259, ICW4.
 call io_delay

 out 0A1h, al ; 从8259, ICW4.
 call io_delay

 mov al, 11111100b
 ;mov al, 11111111b ; 屏蔽主8259所有中断
 out 021h, al ; 主8259, OCW1.
 call io_delay

 mov al, 11111111b ; 屏蔽从8259所有中断
 out 0A1h, al ; 从8259, OCW1.
 call io_delay

 ret

io_delay:
 nop
 nop
 nop
 nop
 nop
 ret

Idt64Ptr:
        dw 4095 ;256*16-1 2047   ;256*8-1
        dq idt64
        dd 0

ALIGN 16
idt64:
times   4096       db 0
 dd 0 ; 没必要,加个保险


setup_idt:
        mov rdx,no_int
        mov eax,180000h
        mov ax,dx     
        mov dx,8e00h
        xor r8,r8   
        mov rdi,idt64
        mov r9,256   
rp_s:
        stosd  ; eax=>[rdi]
        xchg eax,edx
        stosd
        xchg eax,edx
        xchg rax,r8     ; 高32位
 stosq
        xchg rax,r8
        dec r9
        jnz rp_s

;int 0  int 0 除以0出错中断
        mov rdx,int0
        mov r15,0      
        call set_int

;int 1
        mov rdx,int1
        mov r15,1
        call set_int

; 中间的中断偷懒省掉,默认直接iretq返回 

;int 20 time 时钟中断
        mov rdx,time
        mov r15,20h      
        call set_int

;int 21 keybord 键盘中断
        mov rdx,keybord ;_interrupt
        mov r15,21h      
        call set_int

;int 66
        mov rdx,sys_sendrec
        mov r15,66h      
        call set_int

; 中间的中断偷懒省掉,默认直接iretq返回
 
;int ff  ; 最后一个中断
        mov rdx,int0 ; 放在int 0 供测试
        mov r15,0ffh
set_int:
        mov rax,180000h
        mov ax,dx
        mov dx,8e00h
        mov rdi,idt64
        shl r15,4       ; 左移4位等于乘以16
        add rdi,r15
        stosd
        mov eax,edx
        stosd
 xor rax,rax ; 高32位清0
 stosq
        ret

no_int:  ; 默认空置返回
        iretq
int0:        
 iretq

int1:
   iretq

jiffie:
        dq 0

keybord: ; 键盘中断例程

        call _save  
        inc qword [k_reen]
        cmp qword [k_reen],0
        jz .1
        sti
        jmp re_reer
.1:
        mov rsp,_sp
        cli
        in al, 60h
                cmp al,0e0h
                jz .1
                cmp al,0e1h
                jz .1
        call k20 ; 信号转换成字符
        mov al,20h
        out 20h,al 
        mov rsp,[p_proc_ready]
        sti
        jmp re_reer   
key_map:
db 0,10h,'1234567890-=',8,9
db 'qwertyuiop[]',0ah,-1
db 'asdfghjkl;',27h,-1,-1,-1
db 'zxcvbnm,./',-1,'*',-1,20h,-1
dq -1
shift_map:
db 20h,20h,'!@#$%^&*()_+',8,9
db 'QWERTYUIOP{}',0ah,20h
db 'ASDFGHJKL:',22h,20h,20h,20h
db 'ZXCVBNM<>?',20h,'*',20h
dq -1
db '7894561230'
dw 0
mode:
 db 0
leds:  ; 键盘右上角的三只小灯
 db 2
dw 0
k20:
        cmp al,3ah ; caps lock
        jnz k22
        xor byte [leds],4
set_leds: ; 开关小灯
 call kb_wait
 mov al,0edh
        out 60h,al
        call kb_wait
        mov al,byte [leds]
        out 60h,al
        jmp k30
k22:
        cmp al,46h      ;scrll lock
        jnz k22_0
        xor byte [leds],1
        jmp set_leds
k22_0:
        cmp al,45h      ;num lock
        jnz k22_1
        xor byte [leds],2
        jmp set_leds
kb_wait:
        push rax
kb_w:
        in al,64h
        test al,2
        jnz kb_w
        pop rax
        ret
k22_1:
        cmp al,3ah ; display key
        jb k25  ; 能显示的键位

        sub al,3bh      ; f1--f10
        jb end_f
        cmp al,9
        jbe ok_f
        sub al,18
        cmp al,10       ; f11
        jb end_f
        cmp al,11       ; f12
        ja end_f
ok_f:   ; do f1-f12
        push rdi
        push rax
        mov rdi,0b8800h
        stosb  ; f1-f12没有使用
        mov al,7 ; 显示个数和'F'测试
        stosb
        mov al,'F'
        stosb
        mov al,7
        stosb
        pop rax
        pop rdi
        jmp k30
end_f:  ; 处理程序被省略
 jmp k30
k25:
        mov rbx,shift_map ; 先假设是大写 ASDF...
         push rax
        mov al,byte [leds]
        test al,4 ; CapsLock 按了,三个小灯的中间那个亮
         pop rax
        jnz k27  ; 按了,转移
        mov rbx,key_map  ; asdf...
k27:
        xlat
        mov byte [key_char],al
; call dispchar   ; 显字字符
k30:
        ret

 dq 0
key_char:
        db 0
key_buf_con:
dq 0
keybord_buf:
times 90 db 0
key_buf_p:
dq keybord_buf

dwDispPos: ; 屏显地址
dq 0b8000h
dq 0

task_tty0:
dq 0
task_tty:
.9:
        mov r8,84h ;send
        mov r9,qword [task_tty0] ;disp0]
        mov r10,qword [task_fs0]
        mov r14,0
        mov r11,0 ;84h
        mov r12,0
        call sendrec
        mov  qword [key_buf_con],0
        mov rdi,keybord_buf
        mov qword [key_buf_p],rdi
       
;;;...
.8:
        mov al,byte [key_char]
        cmp al,0
        jz .8
        mov byte [key_char],0
        cmp al,8  ; <-
        jz .1
        cmp al,0ah
        jz .2 
        cmp al,0dh
        jz .2
        cmp  qword [key_buf_con],80
        ja .8
        mov rdi,qword [key_buf_p]
        stosb
        mov qword [key_buf_p],rdi
        inc qword  [key_buf_con]
        call dispchar
        jmp .8
.1:
        cmp qword [key_buf_con],0
        jnz .3
        jnp .8
.3:
        dec qword [key_buf_con]
        dec qword [key_buf_con]
        dec qword [dwDispPos]
        dec qword [dwDispPos]
        mov al,20h
        call dispchar
        dec qword [dwDispPos]
        dec qword [dwDispPos]
        jmp .8
.4:
        add qword [dwDispPos],160
        mov al,'@'
        call dispchar

        ret
.2:
        call .4
        mov al,0
        mov rdi,qword [key_buf_p]
        stosb
        mov qword [key_buf_p],rdi

        mov r8,83h ;send
        mov r9,qword [task_tty0] ;disp0]
        mov r10,qword [task_fs0]
        mov r14,8
        mov r11,84h
        mov r12,0
        mov r15,keybord_buf
        call sendrec
        jmp .9

        times 20 dq 0
task_ttysp:
        dq 0
; 显示 RAX 中一个整形数
DispRAX:
 push r8
 mov r8,rax
 shr rax, 32
 call  DispEAX
 mov  rax,r8
 call DispEAX
 pop r8
 ret
DispEAX:
 push r8
 mov r8,rax
 shr rax, 16
 call  DispAX
 mov  rax,r8
 call DispAX
 pop r8
 ret
DispAX:
 push rdx
 mov rdx,rax
 mov al,dh
 call  DispAL
 mov  al,dl
 call DispAL
 pop rdx
 ret
; 显示 AL 中的数字
DispAL: 
 mov ah, al
 shr al, 4
 call DispAL0
 mov  al,ah
DispAL0: 
 and al, 01111b
 cmp al, 9
 ja DispAL1
 add al, '0'
 jmp DispAL2
DispAL1:
 sub al, 0Ah
 add al, 'A'
DispAL2:
dispchar:
 push rdi
 mov rdi, [dwDispPos]
 stosb
 mov  al,7 ; type
 stosb
 mov [dwDispPos], rdi
 pop rdi
 ret
; 显示rsi中的一个字符串
DispStr0:
 push rsi
 push rdi
 push  rbx
 push rax
 mov rdi, [dwDispPos]
DispStr1:
 lodsb
 test al, al
 jz DispStr2
 cmp al, 0Ah ; 是回车吗?
 jnz DispStr3
 push rax
 mov rax, rdi
 mov bl, 160
 div bl
 and rax, 0FFh
 inc rax
 mov bl, 160
 mul bl
 mov rdi, rax
 pop rax
 jmp DispStr1
DispStr3:
 stosb
 mov al,7
 stosb
 jmp DispStr1
DispStr2:
 mov [dwDispPos], rdi
 pop rax
 pop rbx
 pop rdi
 pop rsi
 ret  

_saverip:
        dq 0 ;init0 ;os1
_savecs:
        dq 0 ;18h
_saverflags:
        dq 0 ;202h
_saversp:
        dq 0 ;test0sp
_savess:
        dq 0 ;10h 
_savesp:
        dq 0

_save:
        pop qword [_savesp]
;jmp .1
       pop qword [_saverip]
       pop qword [_savecs]
       pop qword [_saverflags]
       pop qword [_saversp]
       pop qword [_savess] 

        mov rsp,_sp ;[p_proc_ready]
        push qword [_savess]
        push qword [_saversp]
        push qword [_saverflags]
        push qword [_savecs]
        push qword [_saverip]
 push rax
 push rcx
 push rdx
 push rbx
 push rsp
 push rbp
 push rsi
 push rdi
 push r8
 push r9
 push r10
 push r11
 push r12
 push r13
 push r14
 push r15
        mov rcx, proc_table - regs  
        mov rsi,_sp
        sub rsi,rcx
        mov rdi,[p_proc_ready]
        rep movsb

        mov rax, qword [_savesp]
        jmp  rax

times 200 db 0
_sp:
        dq 0,0,0
       
time:
        call _save
        nop
 mov al,20h
 out 20h,al
        inc qword [jiffie]

        inc qword [k_reen]
        cmp qword [k_reen],0
        jnz _t11

        mov rsp,_sp
    push restart
    jmp _t22
_t11:
    push re_reer
_t22:
        call time_call
        ret

time_call:
        inc dword [tickss] ;jiffie]
        sti
                mov rax,[tickss] ;jiffie]
;call DispRAX
                push rdi
                mov rdi,0b8000h  + 3500 ;3200
                stosb
                mov al,7
                stosb  
                pop rdi
        cli
       call schedule 
        ret  

restart:
        call schedule 
        mov rsp,[p_proc_ready]
re_reer:
        dec qword [k_reen]
 pop r15
 pop r14
 pop r13
 pop r12
 pop r11
 pop r10
 pop r9
 pop r8
 pop rdi
 pop rsi
 pop rbp
 pop rbp ;rsp
 pop rbx
 pop rdx
 pop rcx
 pop rax
        iretq
tickss:
        dq 0
;jiffie:
k_reen:
        dq 0


schedule:
        mov r11, [proc_run]
        cmp qword [r11 + 8],0   ;pid
        jz  .1
.3:
        cmp qword [r11 + 48],0  ;p_flage
        jnz .1
        dec qword [r11 + 32]
        ja .2
        mov r10,[r11 + 40]
        mov qword [r11 + 32],r10
.1:
        mov r11,[r11]
        cmp qword [r11 + 8],0
        jz  .1 
        jmp .3
.2:
        mov [proc_run],r11
        add r11,120 ;48
        mov [p_proc_ready],r11
        ret

p_proc_ready:
        dq proc_table + 120
proc_run:
         dq proc_table
proc_head:
         dq proc_table
proc_tail:
         dq proc_table

procss:
next:
        dq 0            ;0
pid:
        dq 0             ;8
p_name:
            times 16 db 0  ;16
ticks:
        dq 0 ;200 ;50            ;32
priority:
        dq 0 ;200 ;50            ;40
p_flags:
        dq 1 ;0            ;48
message:
        dq 0 ;p_msg         ;56
p_recvfrom:
        dq 0             ;64
p_sendto:
        dq 0              ;72
has_int_msg:
        dq 0              ;80
q_sending:
        dq 0 ;proc            ;88
;next_sending:
;parent
        dq 0       ;96
tty:
        dq 0            ;104
;ret message:
        dq 0            ;112
regs:                      ;120 ;48
_r15:
        dq 15h
_r14:
        dq 14h          ;128
_r13:
        dq 13h
_r12:
        dq 12h
_r11:
        dq 11h
_r10:
        dq 10h
_r9:
        dq 9
_r8:
        dq 8
_rdi:
        dq 7
_rsi:
        dq 6
_rbp:
        dq 5
kernel_rsp:
        dq 4
_rbx:
        dq 3
_rdx:
        dq 2
_rcx:
        dq 1
_rax:
        dq -1        ; 240
_rip:
        dq 0 ;init0 ;os1  248
_cs:
        dq 18h       ;256
rflags:
        dq 202h      ;264
_rsp:
        dq 0 ;test0sp   ;272
_ss:
        dq 10h 

proc_table:
        dq 0
           times  ($ - procss) * 11 db 0
        dq 0 

;ax 8 ,cx 9,dx 10,bx11,sp12,bp13,si14,di15
jhg:
        dq 0

rrcx equ proc_table - procss  
init:
        cli

        call time_init
        call fork_init

        call fork
        mov qword [init00],rdi ;r15
        mov qword [rdi + 248], init0 ;test ;[_rip],r15 ;init0
        mov qword [rdi + 272], initsp       
        mov qword [rdi + 48],0 ; p_flags
        mov qword [rdi + 32],10
        mov qword [rdi + 40],10    

        jmp  restart ; -> init0
                     
time_init:
        mov al,34h
        out 43h,al
        mov rax,1193182
        out 40h,al
        mov al,ah
        out 40h,al
        ret
fork_init:
        mov rcx,10
        mov rdi,proc_table
.1:
        mov r15,rdi
        mov rsi,procss ;regs
        push rcx
        mov rcx, rrcx ;proc_table - regs
        rep movsb
        pop rcx
        mov rdi,r15
        add rdi,rrcx
        mov [r15],rdi
        loop .1
        mov qword [r15],proc_table
        ret

init00:
        dq 0
init0: ;test:      
        cli 

        call fork
        mov qword [task_mm0],rdi ; dispchar00],rdi ;r15
        mov  qword [rdi + 248], task_mm ;displaychar0
        mov  qword [rdi + 272], task_mmsp ;testdsp
        mov qword [rdi + 48],84h ;
        mov qword [rdi + 32],10
        mov qword [rdi + 40],10    
       
        call fork
        mov qword [task_fs0],rdi ; dispchar00],rdi ;r15
        mov  qword [rdi + 248], task_fs ;displaychar0
        mov  qword [rdi + 272], task_fssp ;testdsp
        mov qword [rdi + 48],84h ;
        mov qword [rdi + 32],10
        mov qword [rdi + 40],10    
      mov qword [read_keybord],0

        call fork
        mov qword [task_tty0],rdi ; dispchar00],rdi ;r15
        mov  qword [rdi + 248], task_tty ;displaychar0
        mov  qword [rdi + 272], task_ttysp ;testdsp
        mov qword [rdi + 48],84h ;
        mov qword [rdi + 32],10
        mov qword [rdi + 40],10    
      mov qword [read_keybord],0

        call fork
        mov qword [task_sys0],rdi ;disp0],rdi ; dispchar00],rdi ;r15
        mov  qword [rdi + 248], task_sys ;disp ;displaychar0
        mov  qword [rdi + 272], task_syssp ;dispsp ;testdsp
        mov qword [rdi + 48],84h ;
        mov qword [rdi + 32],10
        mov qword [rdi + 40],10    

;;;.......
        mov r8,83h ;send
        mov r9,qword [init00]
        mov r10,'m' ;qword [task_mm0]
        mov r14,1 ;fork
        mov r15,0
        mov r11,84h
        mov r12,0
        call sendrec

        mov r8,84h ;resvi
        mov r9,qword [init00]
        mov r10,'m' ;qword [task_mm0]
        mov r14,0
        mov r15,0
        call sendrec

        mov r9,qword [init00]
        mov r10,qword [r9 + 64] ; recvforn
        mov r15,qword [r10 + 112] ;  loade chile id
        mov qword [chil_id],r15

 
        ;file sys  -> buf
        mov r13,use ;shell ;buf

        mov r8,83h ;seni
        mov r9,qword [init00]
        mov r10,'m' ;qword [task_mm0]
        mov r11,84h ;0 ;run
        mov r14,4 ;exec
        mov r12,0
        call sendrec
 
        mov r8,83h ;send
        mov r9,qword [init00]
        mov r10,qword [chil_id]
        mov r14,0
        mov r15,0
        mov r13,0 ;83
        mov r12,0
        mov r11,0
        call sendrec

        sti
   jmp $

        mov r8,83h ;send
        mov r9,qword [init00]
        mov r10,'m' ;qword [task_mm0]
        mov r14,3 ; wait
        mov r15,qword [chil_id]
        mov r13,0 ;83
        mov r11,86  ; witing
        mov r12,0
        call sendrec
.9:
mov rax,r8
mov rdi,0b8000h
stosb
inc rdi
inc r8
jmp .9

        jmp $
chil_id:
        dq 0

times 20 dq 0
initsp:
        dq 0

fork:
        mov rdi,proc_table
.2:
        cmp qword [rdi + 8],0
        jz .1
        mov rdi,[rdi]
        jmp .2
.1:     
        inc qword [pid_numer]
        mov r15,[pid_numer]
        mov qword [rdi + 8],r15
        ret

pid_numer:
        dq 0
        dq 0,0,0   


sendrec:
        ;r8,func r10,dest r14 r15 ,msg r9, *p
        int 66h ;sys_call
        ret

sys_sendrec:  
        call _save  
        inc qword [k_reen]
        cmp qword [k_reen],0
        jz .1
        sti
        jmp re_reer
.1:
        cli
        mov rsp,_sp
        call sendrec_call
       call schedule 
      mov rsp,[p_proc_ready]
        sti
        jmp restart

sendrec_call:     
        sub r8,83h  ; 83 send
        jz .1
        dec r8      ; 84 receive
        jz .2    
        mov r8,-1
        ret ;error
.1:
        call msg_send
        ret
.2:
        call msg_receive
        ret

msg_send:
        ;deadlock
        cmp r10,'s'
        jz .11
        cmp r10,'m'
        jz .12
        cmp r10,'f'
        jz .13
        jmp .14
.11:
        mov r10,qword [task_sys0]
        jmp .14
.12:
        mov r10,qword [task_mm0]
        jmp .14
.13:
        mov r10,qword [task_fs0]
.14:
        cmp qword [r10 + 48], 84h ;if flag = receiving 84
        jz .1
        cmp qword [r10 + 48], 85h ;if flag = receiving 84
        jz .9
        cmp qword [r10 + 48], 86h ;if flag = receiving 84
        jz .9
       cmp qword [r10 + 64],0 ;if recvfrom = any
        cmp r10,0 ; any
        jnz .2
       
.1:
      mov qword [r10 + 56],0 ;p_msg =0
        mov qword [r10 + 48],r12 ;0 ;p_flag run
        mov qword [r10 + 88],r9
        mov qword [r10 + 64],r9
.2:            
        mov qword [r9 + 112],r15 ;ret_mssg
        mov qword [r9 + 56],r14
        mov qword [r9 + 48],r11 ;83h  ;flag = send ;receiv block
      mov qword [r9 + 96],r13
        mov qword [r9 + 104],r13 ;2
        ret                      
.9:
        mov qword [r9 + 48],r11 ;p_flag run       
        ret

msg_receive:
        cmp r10,'s'
        jz .11
        cmp r10,'m'
        jz .12
        cmp r10,'f'
        jz .13
        jmp .14
.11:
        mov r10,qword [task_sys0]
        jmp .14
.12:
        mov r10,qword [task_mm0]
        jmp .14
.13:
        mov r10,qword [task_fs0]
.14:     
        cmp r10,0 ;any
        jz .1
        cmp qword [r10 + 48],83h ; if flag = send
        jz .2
        cmp qword [r10 + 80],1 ;int 81
        ;jnz .3
.1:
        cmp qword [r9 + 88],0    ;q_sending recvforn
        jnz .5
        mov qword [r9 + 48],84h ; p_flags
        jmp  .4
.5:
        mov r10,qword [r9 + 88]
        mov qword [r9 + 88],0
.2:
        mov qword [r9 + 64],r10
       
        mov r15,qword [r10 + 112]
        mov qword [r9 + 112],r15

        mov r14,qword [r10 + 56]
        mov qword [r9 + 56],r14

       mov r13,qword [r10 + 96]
       mov qword [r9 + 96],r13

        mov r13,qword [r10 + 104]     ;r12
        mov qword [r9 + 104],r13
.4:
        ret


task_sys0: ;disp0: ;sys0:
        dq 0
task_d_dest:
        dq 0
task_sys: ; disp: ;sys:  
.1:
        mov r8,84h ;recev
        mov r9,qword [task_sys0] ; disp0]
        mov r10,0 ;qword [use00] ;0 ;any
        mov r14,0
        mov r15,0
        call sendrec

        mov r9,qword [task_sys0] ;disp0]
        mov r10,qword [r9 + 64]
        mov qword [task_d_dest],r10    
        mov rax,qword [r9 + 56]
        or rax,rax ;0
        jz .5
        dec rax  ;1
        jz .4
        dec rax   ;2
        jz .2
        jmp .3
.4:
        jmp .3
.5:
        jmp .3
.2:
        mov rax,qword [r9 + 112]
        call dispchar

.3:
        mov r8,83h ;send
        mov r9,qword [task_sys0] ;disp0]
        mov r10,qword [task_d_dest]
        mov r14,0
        mov r11,84h
        mov r12,0
        call sendrec          
        jmp .1   
times 20 dq 0
task_syssp: ;dispsp:
        dq 0      

use:
        call .8
        dq 0               ;0
        dq buf             ;8
        db 'hello'     ;16
        dq 0
.8:
        pop rbx

        mov r9,qword [rbx] ;[use00]

        mov r14,0 ;1 ;2 ;mov ah,2   display
        mov r15,0 ;'b' ;mov dl,'a'     msg
        mov r8,84h ;send
        mov r10,0 ;'s' ;qword [task_sys0] ; int 21   task_sys
        mov r11,0 ;84h
        int 66h ;call sendrec  ;int 21

        mov r9,qword [rbx] ;[use00]

        mov r11,qword [r9 + 88] ;q_sending
        mov qword [r9 + 96],r11 ;parent

        mov al,byte [rbx + 16] ;8]
        mov rdi,0b8000h  + 310
        stosb
        mov al,7
        stosb


        mov r15,qword rbx
        add r15,16         
        call write

       mov rdi,qword [rbx + 8]
       mov al,'a'
      stosb
      mov al,0
      stosb
      mov r15,qword [rbx + 8]
      call write


;jmp $

.1:
        mov r14,1
        mov r13,10h ;tty
        mov r15,qword [rbx + 8]
        call read

       mov r15,qword [rbx + 8]
       call write
;jmp .1 ;$

        mov r10,qword [rbx] ;[task_sys0]
      mov rsi,[rbx + 8] ;qword [r10 + 112]      

        mov r15,[rbx + 8] ;qword [r10 + 112]      

      lodsb
        call write

      mov al,'a'
      call write

 ;jmp $ ;
        jmp .1


        mov rdi,buf
        lodsb
        stosb
        mov al,0
        stosb
        call write
;.1:
        mov rdi, [rbx + 8] ;buf
        mov al,'a'
        stosb
        mov al,0
        stosb

        mov r15, rbx ;[rbx + 16]
        add r15,16
        call write
        jmp .1
read:
        mov r9,qword [rbx] ;[use00]
      mov r14,1 ;2 ; write
      mov r15,[rbx + 8] ;buf ;0 ;'w' ;mov dl,'a'     msg
        mov r8,83h ;send
        mov r10,'f' ;qword [task_fs0] ; int 21  
        mov r11,84h
        mov r12,0
      mov r13,10h ;tty
        int 66h ;call sendrec  ;int 21

        mov r9,qword [rbx] ;use00]
        mov r14,1 ;2 ;mov ah,2   display
        mov r15,0 ;'b' ;mov dl,'a'     msg
        mov r8,84h ;revice
        mov r10,'f' ;qword [task_sys0] ; keyb0] ;sys0] ; int 21   task_sys
        int 66h ;call sendrec  ;int 21    
        ret

write:    
        mov r9,qword [rbx] ;qword [use00]
        mov r14,2 ;mov ah,2   display
      mov r15,[rbx + 8] ;rax ;'b' ;mov dl,'a'     msg
        mov r8,83h ;send
        mov r10,'f' ;qword [task_sys0] ; int 21   task_sys
        mov r13,10h ;tty
        mov r11,84h
        mov r12,0
        int 66h ;call sendrec  ;int 21
        ret

        mov r9,qword [rbx] ;[use00]
        mov r14,2 ;mov ah,2   display
        mov r15,'a' ;mov dl,'a'     msg
        mov r8,83h ;send
        mov r10,'f' ;qword [task_sys0] ; int 21   task_sys
        mov r11,84h
        mov r12,0
      int 66h ;call sendrec  ;int 21

       jmp .1

        dq 0

buf:
        times 200 db 0

task_mm0: ;disp0: ;sys0:
        dq 0
task_m_dest:
        dq 0
task_mm: ; disp: ;sys:  
.1:
        mov r8,84h ;recev
        mov r9,qword [task_mm0] ; disp0]
        mov r10,0 ;qword [use00] ;0 ;any
        mov r14,0
        mov r15,0
        call sendrec

        mov r9,qword [task_mm0] ;disp0]
        mov r10,qword [r9 + 64]
        mov qword [task_m_dest],r10    
        mov rax,qword [r9 + 56]
        dec rax ;1 fork
        jz .2
        dec rax  ;2 exit
        jz .3
        dec rax   ;3  wait
        jz .4
        dec rax ;4 exec
        jz .5
        jmp .6

.2:             ; fork
        call do_fork
        mov r15,qword [child00]
        jmp .6

.3:             ; exit
        call do_exit
        jmp .6

.4:             ; wait
        call do_wait
        jmp .6

.5:
        call do_exec
.6:
        mov r8,83h ;send
        mov r9,qword [task_mm0] ;disp0]
        mov r10,qword [task_m_dest]
        mov r14,0
      mov r15,0   
        mov r11,84h
        mov r12,0
        call sendrec
        jmp .1   
times 20 dq 0
task_mmsp: ;dispsp:
        dq 0

child00:
        dq 0   
do_fork:
        call fork
        mov qword [child00],rdi ;r15
        ret

child_base:
        dq 0
do_exec:
        call alloc_mem
        mov qword [child_base],r8
 
        mov r9,qword [task_mm0]
        mov r13,qword [r9 + 104] ; buf   r12
        mov r15,qword [r9 + 112] ; id

        mov rsi,r13
        mov rdi,qword [child_base]
        mov r11,rdi
        mov rcx,100000h ; - 10h ;210h
        rep movsb

        mov qword [r15 + 32], 10  ;tickt
        mov qword [r15 + 40], 10  ;prio
        mov qword [r15 + 56], 0
        mov qword [r15 + 96], r10   ;parten
        mov qword [r15 + 48], 84h ;recv
      add r11,200h
        mov qword [r15 + 248], r11 ; file_exe progran
        mov qword [r11 + 5],r15

        add r11,100000h
        sub r11,100h ;210h
        mov qword [r15 + 272], r11  ;sp     
        ret

mem_base:
        dq 200000h
alloc_mem:
        mov r8,qword [mem_base]
        add qword [mem_base],100000h
        ret

       
do_exit:
        mov r9,qword [task_m_dest]
        mov r15,qword [r9 + 112]
        mov r10,r15
        cmp qword [r10 + 48],85 ;waiting
        jz .1
        mov qword [r9 + 48],86 ;hanging
        ret
.1:
        mov qword [r9 + 8],0
        ret

do_wait:
        mov r9,qword [task_m_dest]
        mov r15,qword [r9 + 112]
        mov r10,r15
        cmp qword [r10 + 48],86 ;hangen
        jz .1
        mov qword [r9 + 48],95 ;waiting
        ret
.1:
        mov qword [r10 + 8],0
      mov qword [r9 + 48],0
mov r9,qword [init00]
mov qword [r9 + 48],0
        ret  
;reply

task_fs0: ;disp0: ;sys0:
        dq 0
task_f_dest:
        dq 0
task_fs: ; disp: ;sys:  
.1:
        mov r8,84h ;recev
        mov r9,qword [task_fs0] ; disp0]
        mov r10,0 ;qword [use00] ;0 ;any
        mov r14,0
        mov r15,0
        call sendrec

        mov r9,qword [task_fs0] ;sys0] ;disp0]
        mov r10,qword [r9 + 64]
        mov qword [task_f_dest],r10    
        mov rax,qword [r9 + 56]
      or rax,rax ;0
      jz .5
        dec al  ;1 read
        jz .8
        dec rax   ;2 write
        jz .2
        dec rax  ;3  open
        jz .3
        dec rax  ;4  close
        jz .4
        dec rax  ;5
        jz .5
        dec rax  ;6
        jz .6
        dec rax  ;7
        jz .7
        dec rax ;8
        jz .10
        jmp .9
.2:
        call do_write
        mov r10,qword [task_f_dest]
        jmp .9 ;11
.3:
        jmp .9
.4:
        jmp .9
.5:
        jmp .9
.6:
        jmp .9
.7:
        jmp .9
.10:    ;keybord
        call reply
        mov r10,qword [read_keybord]

        jmp .9
.8:
        call do_read
        mov r10,qword [task_f_dest]

        jmp .11 ;9        
.9:
        mov r12,0
.11:
        mov r8,83h ;send
        mov r9,qword [task_fs0] ;sys0] ;disp0]
      mov r10,qword [task_f_dest]
        mov r14,0
        mov r11,84h
      mov r12,0
        call sendrec          
        jmp .1   

times 20 dq 0
task_fssp:
        dq 0      
do_write:
        mov rsi,qword [r9 + 112]
        mov r13,qword [r9 + 104]
        sub r13,10h
        jz .2
        ret
.2:
        lodsb
        cmp al,0
        jz .1
        call dispchar
        jmp .2
.1:            
        ret
reply:
        mov rsi,keybord_buf
        mov rdi,qword [use_buf]
        mov rcx,80
        cld
        rep movsb
       mov qword [read_keybord],0
ret

do_read:
        mov r13,qword [r9 + 104]
        sub r13,10h
        jnz .2

        mov r10,qword [task_f_dest]
        mov qword [read_keybord],r10
        mov r15,qword [r10 + 112]
        mov qword [use_buf],r15

        mov r8,83h ;send
        mov r9,qword [task_fs0] ;sys0] ;disp0]
        mov r10,qword [task_tty0]
        mov r14,0
        mov r11,0 ;84h
        mov r12,0
        call sendrec          
       
        mov r12,84h  
        ret
.2:       
        mov r15,file ;'k'
        mov r12,0       
        ret
read_keybord:
        dq 0
use_buf:
        dq 0
file:
        db 'k'

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有