Subversion Repositories Kolibri OS

Rev

Rev 430 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. MEM_WB     equ 6               ;write-back memory
  3. MEM_WC     equ 1               ;write combined memory
  4. MEM_UC     equ 0               ;uncached memory
  5.  
  6. align 4
  7. proc mem_test
  8.  
  9.            mov eax, cr0
  10.            and eax, not (CR0_CD+CR0_NW)
  11.            or eax, CR0_CD         ;disable caching
  12.            mov cr0, eax
  13.            wbinvd                 ;invalidate cache
  14.  
  15.            xor edi, edi
  16.            mov ebx, 'TEST'
  17. @@:
  18.            add edi, 0x100000
  19.            xchg ebx, dword [edi]
  20.            cmp dword [edi], 'TEST'
  21.            xchg ebx, dword [edi]
  22.            je @b
  23.            mov [MEM_AMOUNT-OS_BASE], edi
  24.  
  25.            and eax, not (CR0_CD+CR0_NW)  ;enable caching
  26.            mov cr0, eax
  27.            mov eax, edi
  28.            ret
  29. endp
  30.  
  31. align 4
  32. proc init_mem
  33.            mov eax, [MEM_AMOUNT-OS_BASE]
  34.            mov [pg_data.mem_amount-OS_BASE], eax
  35.  
  36.            shr eax, 12
  37.            mov edx, eax
  38.            mov [pg_data.pages_count-OS_BASE], eax
  39.            shr eax, 3
  40.            mov [pg_data.pagemap_size-OS_BASE], eax
  41.  
  42.            cmp edx, (OS_BASE/4096)
  43.            jbe @F
  44.            mov edx, (OS_BASE/4096)
  45.            jmp .set
  46. @@:
  47.            cmp edx, (HEAP_MIN_SIZE/4096)
  48.            jae .set
  49.            mov edx, (HEAP_MIN_SIZE/4096)
  50. .set:
  51.            mov [pg_data.kernel_pages-OS_BASE], edx
  52.            shr edx, 10
  53.            mov [pg_data.kernel_tables-OS_BASE], edx
  54.  
  55.            xor eax, eax
  56.            mov edi, sys_pgdir-OS_BASE
  57.            mov ecx, 4096/4
  58.            cld
  59.            rep stosd
  60.  
  61.            mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20)
  62.            bt [cpu_caps-OS_BASE], CAPS_PSE
  63.            jnc .no_PSE
  64.  
  65.            mov ebx, cr4
  66.            or ebx, CR4_PSE
  67.            mov eax, PG_LARGE+PG_SW
  68.  
  69.            bt [cpu_caps-OS_BASE], CAPS_PGE
  70.            jnc @F
  71.  
  72.            or eax, PG_GLOBAL
  73.            or ebx, CR4_PGE
  74. @@:
  75.            mov cr4, ebx
  76.            sub [pg_data.kernel_tables-OS_BASE], 1
  77.  
  78.            mov [edx], eax
  79.            add eax, 0x00400000
  80. ;           mov [edx+4], eax
  81.            add edx, 4
  82.  
  83.            mov eax, 0x400000+PG_SW
  84.            mov ecx, (tmp_page_tab-0x400000)/4096
  85.            jmp .map_low
  86. .no_PSE:
  87.            mov eax, PG_SW
  88.            mov ecx, tmp_page_tab/4096
  89. .map_low:
  90.            mov edi, tmp_page_tab
  91. @@:                                   ;
  92.            stosd
  93.            add eax, 0x1000
  94.            dec ecx
  95.            jnz @B
  96.  
  97.            mov ecx, [pg_data.kernel_tables-OS_BASE]
  98.            shl ecx, 10
  99.            xor eax, eax
  100.            rep stosd
  101.  
  102.            mov ecx, [pg_data.kernel_tables-OS_BASE]
  103.            mov eax, tmp_page_tab+PG_SW
  104.            mov edi, edx
  105.  
  106. .map_kernel_tabs:
  107.  
  108.            stosd
  109.            add eax, 0x1000
  110.            dec ecx
  111.            jnz .map_kernel_tabs
  112.  
  113.            mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
  114.  
  115.            mov edi, (sys_pgdir-OS_BASE)
  116.            lea esi, [edi+(OS_BASE shr 20)]
  117.            movsd
  118.            movsd
  119.            movsd
  120.            ret
  121. endp
  122.  
  123. align 4
  124. proc init_page_map
  125.  
  126.            mov edi, sys_pgmap-OS_BASE
  127.            mov ecx, ((HEAP_BASE-OS_BASE)/4096)/32      ;384/4
  128.            mov ebx, ecx
  129.            xor eax,eax
  130.            cld
  131.            rep stosd
  132.  
  133.            not eax
  134.            mov ecx, [pg_data.pagemap_size-OS_BASE]
  135.            sub ecx, ebx
  136.            shr ecx, 2
  137.            rep stosd
  138.  
  139.            lea edi, [sys_pgmap-OS_BASE+ebx*4]         ;+384
  140.            mov edx, [pg_data.pages_count-OS_BASE]
  141.            mov ecx, [pg_data.kernel_tables-OS_BASE]
  142.            add ecx, ((HEAP_BASE-OS_BASE)/4096) and 31
  143.            sub edx, (HEAP_BASE-OS_BASE)/4096
  144.            sub edx, ecx
  145.            mov [pg_data.pages_free-OS_BASE], edx
  146.  
  147.            xor eax, eax
  148.            mov ebx, ecx
  149.            shr ecx, 5
  150.            rep stosd
  151.  
  152.            not eax
  153.            mov ecx, ebx
  154.            and ecx, 31
  155.            shl eax, cl
  156.            mov [edi], eax
  157.            add edi, OS_BASE
  158.            mov [page_start-OS_BASE], edi;
  159.  
  160.            mov ebx, sys_pgmap
  161.            add ebx, [pg_data.pagemap_size-OS_BASE]
  162.            mov [page_end-OS_BASE], ebx
  163.  
  164.            mov [pg_data.pg_mutex-OS_BASE], 0
  165.  
  166.            ret
  167. endp
  168.  
  169. align 4
  170. proc test_cpu
  171.            locals
  172.               cpu_type   dd ?
  173.               cpu_id     dd ?
  174.               cpu_Intel  dd ?
  175.               cpu_AMD    dd ?
  176.            endl
  177.  
  178.            mov [cpu_type], 0
  179.            xor eax, eax
  180.            mov [cpu_caps-OS_BASE], eax
  181.            mov [cpu_caps+4-OS_BASE], eax
  182.  
  183.            pushfd
  184.            pop eax
  185.            mov ecx, eax
  186.            xor eax, 0x40000
  187.            push eax
  188.            popfd
  189.            pushfd
  190.            pop eax
  191.            xor eax, ecx
  192.            mov [cpu_type], CPU_386
  193.            jz .end_cpuid
  194.            push ecx
  195.            popfd
  196.  
  197.            mov [cpu_type], CPU_486
  198.            mov eax, ecx
  199.            xor eax, 0x200000
  200.            push eax
  201.            popfd
  202.            pushfd
  203.            pop eax
  204.            xor eax, ecx
  205.            je .end_cpuid
  206.            mov [cpu_id], 1
  207.  
  208.            xor eax, eax
  209.            cpuid
  210.  
  211.            mov [cpu_vendor-OS_BASE], ebx
  212.            mov [cpu_vendor+4-OS_BASE], edx
  213.            mov [cpu_vendor+8-OS_BASE], ecx
  214.            cmp ebx, dword [intel_str-OS_BASE]
  215.            jne .check_AMD
  216.            cmp edx, dword [intel_str+4-OS_BASE]
  217.            jne .check_AMD
  218.            cmp ecx, dword [intel_str+8-OS_BASE]
  219.            jne .check_AMD
  220.            mov [cpu_Intel], 1
  221.            cmp eax, 1
  222.            jl .end_cpuid
  223.            mov eax, 1
  224.            cpuid
  225.            mov [cpu_sign-OS_BASE], eax
  226.            mov [cpu_info-OS_BASE],  ebx
  227.            mov [cpu_caps-OS_BASE],  edx
  228.            mov [cpu_caps+4-OS_BASE],ecx
  229.  
  230.            shr eax, 8
  231.            and eax, 0x0f
  232.            ret
  233. .end_cpuid:
  234.            mov eax, [cpu_type]
  235.            ret
  236.  
  237. .check_AMD:
  238.            cmp ebx, dword [AMD_str-OS_BASE]
  239.            jne .unknown
  240.            cmp edx, dword [AMD_str+4-OS_BASE]
  241.            jne .unknown
  242.            cmp ecx, dword [AMD_str+8-OS_BASE]
  243.            jne .unknown
  244.            mov [cpu_AMD], 1
  245.            cmp eax, 1
  246.            jl .unknown
  247.            mov eax, 1
  248.            cpuid
  249.            mov [cpu_sign-OS_BASE], eax
  250.            mov [cpu_info-OS_BASE],  ebx
  251.            mov [cpu_caps-OS_BASE],  edx
  252.            mov [cpu_caps+4-OS_BASE],ecx
  253.            shr eax, 8
  254.            and eax, 0x0f
  255.            ret
  256. .unknown:
  257.            mov eax, 1
  258.            cpuid
  259.            mov [cpu_sign-OS_BASE], eax
  260.            mov [cpu_info-OS_BASE],  ebx
  261.            mov [cpu_caps-OS_BASE],  edx
  262.            mov [cpu_caps+4-OS_BASE],ecx
  263.            shr eax, 8
  264.            and eax, 0x0f
  265.            ret
  266. endp
  267.  
  268.