Subversion Repositories Kolibri OS

Rev

Rev 465 | Rev 581 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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