⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys32.inc

📁 Menuet 操作系统源代码。 非常难得的东西
💻 INC
📖 第 1 页 / 共 5 页
字号:
        jmp   i_u_errorhandle
i_unknownf2:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf3:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf4:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf5:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf6:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf7:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf8:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf9:
        push  dword $
        jmp   i_u_errorhandle
i_unknownfa:
        push  dword $
        jmp   i_u_errorhandle
i_unknownfb:
        push  dword $
        jmp   i_u_errorhandle
i_unknownfc:
        push  dword $
        jmp   i_u_errorhandle
i_unknownfd:
        push  dword $
        jmp   i_u_errorhandle
i_unknownfe:
        push  dword $
        jmp   i_u_errorhandle
i_unknownff:
        push  dword $
        jmp   i_u_errorhandle
   
   
i_u_errorhandle:
   
        cli
   
        pop   eax

        sti

        jmp   $

   

find_free_mem:

        push   eax
        push   ebx
        push   ecx
        push   edx
        push   edi

        call   find_free_process_slot
        mov    eax,[new_process_place]

        cmp    eax,max_processes
        jge    find_free_ret_2
   
        cmp    [thread_create],1
        je     thread_c
   
        mov    esi,[0xfe84]
        add    edi,esi
        dec    edi

        mov    eax,2
        cmp    dword [0x3004],1
        je     findf4
   
     fgdt:
   
        mov    edx,2
   
      findgdtl1:

        mov    ecx,edx
        shl    ecx,3

        ; eax run base -> ebx limit
   
        mov    al,[ecx+gdts+ app_code-3 +4]
        mov    ah,[ecx+gdts+ app_code-3 +7]
        shl    eax,16
        mov    ax,[ecx+gdts+ app_code-3 +2]
   
        movzx  ebx,word [ecx+gdts+ app_code-3 +0]
        shl    ebx,12
        add    ebx,eax
   
        cmp    eax,edi
        jg     findfl3
        cmp    ebx,esi
        jb     findfl3
   
        add    esi,4096
        add    edi,4096
   
        cmp    edi,[0xfe8c]        ; < c_memory
        jbe    fgdt
   
        jmp    find_free_ret_2
   
      findfl3:
   
        inc    edx
        cmp    edx,[check_processes]
        jbe    findgdtl1
   
     findfl1:
     thread_c:
   
         mov    eax,[new_process_place]

     findf4:

        mov    [first_gdt_search],eax
        mov    [gdt_place],eax
   
        mov    ecx,eax
        shl    ecx,3
   
        inc    edi                  
        sub    edi,esi
        add    edi,4095
        shr    edi,12
        dec    edi
   
        ; code
   
        mov    eax,esi
        mov    ebx,edi
   
        mov    [ecx+gdts+ app_code-3 +2], ax                   ;  base  0:15
        shr    eax,16
        mov    [ecx+gdts+ app_code-3 +4], al                   ;  base  23:16
        mov    [ecx+gdts+ app_code-3 +7], ah                   ;  base  31:24
        mov    [ecx+gdts+ app_code-3 +0], bx                   ;  limit
        mov    [ecx+gdts+ app_code-3 +5], word 11010000b *256 +11111010b
   
        ; data
   
        mov    eax,esi
        mov    [ecx+gdts+ app_data-3 +2], ax                   ;  base  0:15
        shr    eax,16
        mov    [ecx+gdts+ app_data-3 +4], al                   ;  base  23:16
        mov    [ecx+gdts+ app_data-3 +7], ah                   ;  base  31:24
        mov    [ecx+gdts+ app_data-3 +0], bx                   ;  limit
        mov    [ecx+gdts+ app_data-3 +5], word 11010000b *256 +11110010b
   
        push   esi
        mov    esi,process_loading
        call   sys_msg_board_str
        pop    esi
   
      find_free_ret:
   
        pop    edi
        pop    edx
        pop    ecx
        pop    ebx
        pop    eax
        ret

      find_free_ret_2:

        cmp    [dec3004],0
        je     no3004inc
        inc    dword [0x3004]
      no3004inc:
   
        pop    edi
        pop    edx
        pop    ecx
        pop    ebx
        pop    eax
        mov    esi,0               
        ret
   
   
get_app_params:
   
    push eax
   
    cmp  [0x90000+6],word '00'
    jne  no_00_header
   
    mov  eax,[0x90000+12]
    mov  [app_start],eax
    mov  eax,[0x90000+16]
    mov  [app_i_end],eax
    mov  eax,[0x90000+20]
    mov  [app_mem],eax
    shr  eax,1
    sub  eax,0x10
    mov  [app_esp],eax
    mov  eax,[0x90000+24]
    mov  [app_i_param],eax
    mov  [app_i_icon],dword 0
   
    pop  eax
    mov  esi,1
    ret
   
  no_00_header:
   
   
    cmp  [0x90000+6],word '01'
    jne  no_01_header
   
    mov  eax,[0x90000+12]
    mov  [app_start],eax
    mov  eax,[0x90000+16]
    mov  [app_i_end],eax
    mov  eax,[0x90000+20]
    mov  [app_mem],eax
    mov  eax,[0x90000+24]
    mov  [app_esp],eax
    mov  eax,[0x90000+28]
    mov  [app_i_param],eax
    mov  eax,[0x90000+32]
    mov  [app_i_icon],eax
   
    pop  eax
    mov  esi,1
    ret
   
   no_01_header:
   
    pop  eax
    mov  esi,0
    ret
   
   
start_application_fl:

    cli
    cmp   [application_table_status],0
    je    stfl9
    sti
    call  change_task
    jmp   start_application_fl
  stfl9:

    mov   [application_table_status],1
    mov   [thread_create],0

    push  ebx
    push  eax
   
    mov   ebx,1
    mov   ecx,2
    mov   edx,0x90000
    mov   esi,12
    cli
    call  fileread
    cli
    cmp   eax,0
    jne   noflrun
    cmp   [0x90000+0],dword 'MENU'
    jnz   noflrun
    cmp   [0x90000+4],word  'ET'
    jnz   noflrun
    call  get_app_params
    cmp   esi,0
    je    noflrun
    mov   edi,[app_mem]
    call  find_free_mem
    cmp   esi,0
    jne   start_app_c
   
  noflrun:
   
    pop   eax
    pop   ebx
    mov   eax,-1
    mov   [application_table_status],0
    sti
    ret
   
  start_app_c:

    mov   [app_mem_pos],esi
   
    mov   edi,[app_mem_pos]      ; clear run location
    mov   ecx,[app_mem]
    mov   eax,0x0
    cld
    rep   stosb
   
    mov   eax,[esp+0]            ; read all of file to it's run location
    mov   ebx,0
    mov   ecx,-1
    mov   edx,[app_mem_pos]
    mov   esi,12
    cli
    call  fileread
    cli

    jmp   add_app_parameters

   
start_application_hd:
   
    cli
    cmp   [application_table_status],0
    je    sthd9
    sti
    call  change_task
    jmp   start_application_hd
  sthd9:
    mov   [application_table_status],1
    sti
   
    mov   [thread_create],0
   
    push  ebx   ; file length
    push  eax   ; file name    - abs address
    push  ecx   ; work area    - abs address
   
    mov   esi,ecx
   
    mov   ecx,1
    mov   edx,1

    pusha
    call  read_hd_file
    cmp   eax,0
    je    rhdfl5   
    popa
   
    add   esp,4*3
    mov   eax,-1
    mov   [application_table_status],0
    ret
   
  rhdfl5:
    popa
   
    cmp   [esi+1024+0],dword 'MENU'
    jnz   nohdrun
    cmp   [esi+1024+4],word  'ET'
    jnz   nohdrun
   
    add   esi,1024
    mov   edi,0x90000
    mov   ecx,512/4
    cld
    rep   movsd
   
    call  get_app_params
    cmp   esi,0
    je    nohdrun
   
    mov   edi,[app_mem]
    call  find_free_mem
    cmp   esi,0
    jne   read_file_to_place
   
  nohdrun:
   
    add   esp,4*3
    mov   eax,1
    mov   [application_table_status],0
    sti
    ret
   
  read_file_to_place:
   
    cli
   
    mov   [thread_create],0
    mov   [app_mem_pos],esi
   
    pop   esi
   
    mov   edi,[app_mem_pos]            ; clear run location
    mov   ecx,[app_mem]
    mov   eax,0x0
    cld
    rep   stosb
   
    mov   ecx,1                        ; read the file to its run-location
   
  hdnw:
   
    push  ecx
    push  esi
    mov   eax,[esp+8]
    mov   ebx,[esp+12]
    mov   edx,1
    call  read_hd_file
    pop   esi
    pop   ecx
    cmp   eax,0
    jne   stnshd
   
    push  ecx
    mov   eax,esi
    add   eax,1024
    mov   ebx,ecx
    sub   ebx,1
    shl   ebx,9
    add   ebx,[app_mem_pos]
    mov   ecx,512
    call  memmove
    pop   ecx
   
    add   ecx,1
    jmp   hdnw
   
  stnshd:
   
    cli
    add   esp,4*2
    push  dword 0
    push  dword hd_app_string
    jmp   add_app_parameters


threadstring       dd  0x0
new_process_place  dd  0x0
check_processes    dd  0x0
dec3004            db  0x0
hd_app_string      db  'HDAPP       '
   
app_start    dd  0x0
app_i_end    dd  0x0
app_mem      dd  0x0
app_esp      dd  0x0
app_i_param  dd  0x0
app_i_icon   dd  0x0
app_mem_pos  dd  0x0
   
process_loading  db 'K : Process - loading ',13,10,0
process_running  db 'K : Process - done',13,10,0
first_gdt_search dd 0x2
thread_create    dd 0x0
gdt_place        dd 0x0

   
sys_threads:
   
; eax=1 create thread
;
;   ebx=thread start
;   ecx=thread stack value
;
; on return : eax = pid
   
    cli
    cmp   [application_table_status],0
    je    stth9
    sti
    call  change_task
    jmp   sys_threads
  stth9:
    mov   [application_table_status],1
    sti
   
    cmp  eax,1
    jne  no_sys_thread_create
    cli
   
    mov  eax,[0x3010]
    mov  eax,[eax+0x10]
    mov  [app_mem_pos],eax
   
    mov  [app_i_param],0
    mov  [app_i_icon],0
   
    mov  [app_start],ebx
    mov  [app_esp],ecx
   
    mov  ebx,[0x3000]
    shl  ebx,8
    add  ebx,0x80000
    mov  [threadstring],ebx
    mov  ebx,[ebx+0x8c]
    mov  [app_mem],ebx
   
    mov  esi,[app_mem_pos]
    mov  edi,[app_mem]
    add  edi,esi
    dec  edi
    mov  [thread_create],1
    call find_free_mem
    cmp  esi,0
    jne  th_cr1
    mov  [application_table_status],0
    mov  eax,1   ; no free memory
    sti
    ret
  th_cr1:
    push dword 0
    push dword [threadstring]
    jmp  add_app_parameters
  no_sys_thread_create:
   
    mov  eax,-1
    mov  [application_table_status],0
    ret
   

find_free_process_slot:

    pusha

    mov   ebx,[0x3004]
    mov   [check_processes],ebx
    inc   ebx
    mov   [new_process_place],ebx

    mov   ebx,2
  
  newfps:

    mov   eax,ebx
    imul  eax,0x20
    add   eax,0x3000+0xa
    cmp   [eax],byte 9
    je    ffpl
    
    inc   ebx
    cmp   ebx,[0x3004]
    jbe   newfps

    mov   [dec3004],0

    popa
    ret

  ffpl:
   
    mov   [dec3004],1
    dec   dword [0x3004]
    mov   [new_process_place],ebx

    popa
    ret

   
add_app_parameters:

; returns:  eax = pid or -1 if unsuccesfull

    cmp   [app_i_param],dword 0     ; parameter
    jz    no_app_params
    mov   eax,0
    mov   edi,[app_i_param]
    add   edi,[app_mem_pos]
    mov   ecx,256/4
    cld
    rep   stosd
    mov   esi,[esp+4]
    cmp   esi,0
    jz    no_app_params
    mov   eax,[app_i_param]
    add   eax,[app_mem_pos]
    mov   edi,eax
    mov   ecx,256
    cld
  app_new_param:
    cmp   [esi],byte 0
    jz    no_app_params
    movsb
    loop  app_new_param
  no_app_params:

    inc   dword [0x3004]            ; increase number of processes
    mov   ebx,[new_process_place]
   
    mov   edi,ebx        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -