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

📄 sys32.inc

📁 MenuetOS是一个用汇编开发的32/64位PC操作系统
💻 INC
📖 第 1 页 / 共 5 页
字号:
        jmp   i_u_errorhandle
i_unknowne4:
        push  dword $
        jmp   i_u_errorhandle
i_unknowne5:
        push  dword $
        jmp   i_u_errorhandle
i_unknowne6:
        push  dword $
        jmp   i_u_errorhandle
i_unknowne7:
        push  dword $
        jmp   i_u_errorhandle
i_unknowne8:
        push  dword $
        jmp   i_u_errorhandle
i_unknowne9:
        push  dword $
        jmp   i_u_errorhandle
i_unknownea:
        push  dword $
        jmp   i_u_errorhandle
i_unknowneb:
        push  dword $
        jmp   i_u_errorhandle
i_unknownec:
        push  dword $
        jmp   i_u_errorhandle
i_unknowned:
        push  dword $
        jmp   i_u_errorhandle
i_unknownee:
        push  dword $
        jmp   i_u_errorhandle
i_unknownef:
        push  dword $
        jmp   i_u_errorhandle



i_unknownf0:
        push  dword $
        jmp   i_u_errorhandle
i_unknownf1:
        push  dword $
        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   $





compare_to_thread:

         push ebx

         mov  eax,edx
         imul eax,8
         add  eax,gdts+ app_code-3
         mov  ebx,[eax]
         cmp  ebx,[old_code_0]
         jne  ctt0
         mov  ebx,[eax+4]
         cmp  ebx,[old_code_1]
         jne  ctt0

         pop  ebx
         mov  eax,1
         ret

       ctt0:

         pop  ebx
         mov  eax,0
         ret



check_for_thread_mem:

         pusha

         mov  ecx,[0x3004]
       cftm0:
         mov  eax,ecx
         imul eax,8
         add  eax,gdts+ app_code-3
         mov  ebx,[eax]
         cmp  ebx,[old_code_0]
         jne  cftm1
         mov  ebx,[eax+4]
         cmp  ebx,[old_code_1]
         jne  cftm1

         mov  eax,ecx  ; new code segments
         imul eax,8
         add  eax,gdts+ app_code-3

         mov  ebx,[new_code_0]
         mov  [eax],ebx
         mov  ebx,[new_code_1]
         mov  [eax+4],ebx

         mov  eax,ecx  ; new data segments
         imul eax,8
         add  eax,gdts+ app_data-3

         mov  ebx,[new_data_0]
         mov  [eax],ebx
         mov  ebx,[new_data_1]
         mov  [eax+4],ebx

         cmp  [new_pos],0   ; new memory position segments
         je   no_new_postition_for_thread
         mov  eax,ecx
         imul eax,32
         add  eax,0x3000
         mov  ebx,[new_pos]
         mov  [eax+0x10],ebx
       no_new_postition_for_thread:

         mov  eax,ecx       ; new amount of memory
         imul eax,256
         add  eax,0x80000
         mov  ebx,[new_amount]
         mov  [eax+0x8C],ebx

       cftm1:

         dec  ecx
         jnz  cftm0

         popa

         ret


save_for_thread_check:

        ; save for thread check

        pusha
        mov    esi,[0x3000]
        imul   esi,8
        add    esi,gdts+ app_code-3 +0
        mov    edi,old_code_0
        mov    ecx,8
        cld
        rep    movsb
        popa

        ret


save_new_position_for_threads:

        ; new code segment for thread check
        pusha
        mov    esi,[0x3000]
        imul   esi,8
        add    esi,gdts+ app_code-3 +0
        mov    edi,new_code_0
        mov    ecx,8
        cld
        rep    movsb
        popa

        ; new data segment for thread check
        pusha
        mov    esi,[0x3000]
        imul   esi,8
        add    esi,gdts+ app_data-3 +0
        mov    edi,new_data_0
        mov    ecx,8
        cld
        rep    movsb
        popa

        ret


set_application_table_status:

        push eax

        mov  eax,[0x3000]
        imul eax,32
        add  eax,0x3000+4
        mov  eax,[eax]

        mov  [application_table_status],eax

        pop  eax

        ret


clear_application_table_status:

        push eax

        mov  eax,[0x3000]
        imul eax,32
        add  eax,0x3000+4
        mov  eax,[eax]

        cmp  eax,[application_table_status]
        jne  apptsl1
        mov  [application_table_status],0
      apptsl1:

        pop  eax

        ret


old_code_0 dd 0x0
old_code_1 dd 0x0

;

new_code_0 dd 0x0
new_code_1 dd 0x0

new_data_0 dd 0x0
new_data_1 dd 0x0

new_pos    dd 0x0
new_amount dd 0x0


sys_resize_app_memory:

        ; eax = 1 - resize
        ;     ebx = new amount of memory

        cmp    eax,1
        jne    no_application_mem_resize

        add    ebx,4095
        shr    ebx,12
        shl    ebx,12
        mov    ebp,ebx

        ; wait for process table to be free

      rsm0:

        cli
        cmp   [application_table_status],0
        je    rsm1
        sti
        call  change_task
        jmp   rsm0

      rsm1:

        call  set_application_table_status
        sti

        cmp    ebx,0 ; other than zero
        je     mem_resize_unsuccess

        call   save_for_thread_check

        ; find a free place

        mov    esi,[0xfe84]  ; application memory start
        mov    edi,ebp
        add    edi,esi
        dec    edi

      rfgdt:

        mov    edx,2

      rfindgdtl1:

        call   compare_to_thread
        cmp    eax,1
        je     rfindfl3

        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     rfindfl3
        cmp    ebx,esi
        jb     rfindfl3

        add    esi,4096
        add    edi,4096

        cmp    edi,[0xfe8c]        ; < c_memory
        jbe    rfgdt

        jmp    rfind_free_ret_2   ;; not enough memory

      rfindfl3:

        inc    edx
        cmp    edx,[0x3004]
        jbe    rfindgdtl1

     rfindfl1:
     rthread_c:

        mov    ecx,[0x3000]
        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

        ; 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

        movzx  edx,word [ecx+gdts+ app_code-3 +0]         ;  save limit

        mov    [ecx+gdts+ app_data-3 +0], bx              ;  limit

        and    ebx,0xffff

        cmp    ebx,edx  ; copy smaller from memory sizes
        jge    noedxebxxchg
        mov    edx,ebx
      noedxebxxchg:

        movzx  ecx,dx
        shl    ecx,12
        add    ecx,4096

        mov    edi,esi

        mov    eax,[0x3010]
        mov    esi,[eax+0x10]

        mov    [eax+0x10],edi  ; new memory position

        mov    eax,[0x3000]    ; new memory size
        shl    eax,8
        add    eax,0x80000
        mov    [eax+0x8c],ebp

        mov    [new_pos],edi    ; new position for threads
        mov    [new_amount],ebp ; new amount of mem for threads

        cmp    esi,edi
        je     no_app_move

        cld
        rep    movsb           ; move the app image to the new position

      no_app_move:

        call   save_new_position_for_threads
        call   check_for_thread_mem

        mov    [application_table_status],0

        mov    [esp+36],dword 0 ; eax <- 0 ; successfull

        ret

     rfind_free_ret_2:

     mem_resize_unsuccess:

        mov    [application_table_status],0

        mov    [esp+36],dword 1 ; eax <- 1 ; unsuccessfull

        ret

     no_application_mem_resize:


        ret



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
        jg     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

⌨️ 快捷键说明

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