Subversion Repositories Kolibri OS

Rev

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