Subversion Repositories Kolibri OS

Rev

Rev 432 | 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.            lodsd
  118.            and eax, not PG_GLOBAL
  119.            stosd
  120.            lodsd
  121.            and eax, not PG_GLOBAL
  122.            stosd
  123.            lodsd
  124.            and eax, not PG_GLOBAL
  125.            stosd
  126.            ret
  127. endp
  128.  
  129. align 4
  130. proc init_page_map
  131.  
  132.            mov edi, sys_pgmap-OS_BASE
  133.            mov ecx, ((HEAP_BASE-OS_BASE)/4096)/32      ;384/4
  134.            mov ebx, ecx
  135.            xor eax,eax
  136.            cld
  137.            rep stosd
  138.  
  139.            not eax
  140.            mov ecx, [pg_data.pagemap_size-OS_BASE]
  141.            sub ecx, ebx
  142.            shr ecx, 2
  143.            rep stosd
  144.  
  145.            lea edi, [sys_pgmap-OS_BASE+ebx*4]         ;+384
  146.            mov edx, [pg_data.pages_count-OS_BASE]
  147.            mov ecx, [pg_data.kernel_tables-OS_BASE]
  148.            add ecx, ((HEAP_BASE-OS_BASE)/4096) and 31
  149.            sub edx, (HEAP_BASE-OS_BASE)/4096
  150.            sub edx, ecx
  151.            mov [pg_data.pages_free-OS_BASE], edx
  152.  
  153.            xor eax, eax
  154.            mov ebx, ecx
  155.            shr ecx, 5
  156.            rep stosd
  157.  
  158.            not eax
  159.            mov ecx, ebx
  160.            and ecx, 31
  161.            shl eax, cl
  162.            mov [edi], eax
  163.            add edi, OS_BASE
  164.            mov [page_start-OS_BASE], edi;
  165.  
  166.            mov ebx, sys_pgmap
  167.            add ebx, [pg_data.pagemap_size-OS_BASE]
  168.            mov [page_end-OS_BASE], ebx
  169.  
  170.            mov [pg_data.pg_mutex-OS_BASE], 0
  171.  
  172.            ret
  173. endp
  174.  
  175. align 4
  176. proc test_cpu
  177.            locals
  178.               cpu_type   dd ?
  179.               cpu_id     dd ?
  180.               cpu_Intel  dd ?
  181.               cpu_AMD    dd ?
  182.            endl
  183.  
  184.            mov [cpu_type], 0
  185.            xor eax, eax
  186.            mov [cpu_caps-OS_BASE], eax
  187.            mov [cpu_caps+4-OS_BASE], eax
  188.  
  189.            pushfd
  190.            pop eax
  191.            mov ecx, eax
  192.            xor eax, 0x40000
  193.            push eax
  194.            popfd
  195.            pushfd
  196.            pop eax
  197.            xor eax, ecx
  198.            mov [cpu_type], CPU_386
  199.            jz .end_cpuid
  200.            push ecx
  201.            popfd
  202.  
  203.            mov [cpu_type], CPU_486
  204.            mov eax, ecx
  205.            xor eax, 0x200000
  206.            push eax
  207.            popfd
  208.            pushfd
  209.            pop eax
  210.            xor eax, ecx
  211.            je .end_cpuid
  212.            mov [cpu_id], 1
  213.  
  214.            xor eax, eax
  215.            cpuid
  216.  
  217.            mov [cpu_vendor-OS_BASE], ebx
  218.            mov [cpu_vendor+4-OS_BASE], edx
  219.            mov [cpu_vendor+8-OS_BASE], ecx
  220.            cmp ebx, dword [intel_str-OS_BASE]
  221.            jne .check_AMD
  222.            cmp edx, dword [intel_str+4-OS_BASE]
  223.            jne .check_AMD
  224.            cmp ecx, dword [intel_str+8-OS_BASE]
  225.            jne .check_AMD
  226.            mov [cpu_Intel], 1
  227.            cmp eax, 1
  228.            jl .end_cpuid
  229.            mov eax, 1
  230.            cpuid
  231.            mov [cpu_sign-OS_BASE], eax
  232.            mov [cpu_info-OS_BASE],  ebx
  233.            mov [cpu_caps-OS_BASE],  edx
  234.            mov [cpu_caps+4-OS_BASE],ecx
  235.  
  236.            shr eax, 8
  237.            and eax, 0x0f
  238.            ret
  239. .end_cpuid:
  240.            mov eax, [cpu_type]
  241.            ret
  242.  
  243. .check_AMD:
  244.            cmp ebx, dword [AMD_str-OS_BASE]
  245.            jne .unknown
  246.            cmp edx, dword [AMD_str+4-OS_BASE]
  247.            jne .unknown
  248.            cmp ecx, dword [AMD_str+8-OS_BASE]
  249.            jne .unknown
  250.            mov [cpu_AMD], 1
  251.            cmp eax, 1
  252.            jl .unknown
  253.            mov eax, 1
  254.            cpuid
  255.            mov [cpu_sign-OS_BASE], eax
  256.            mov [cpu_info-OS_BASE],  ebx
  257.            mov [cpu_caps-OS_BASE],  edx
  258.            mov [cpu_caps+4-OS_BASE],ecx
  259.            shr eax, 8
  260.            and eax, 0x0f
  261.            ret
  262. .unknown:
  263.            mov eax, 1
  264.            cpuid
  265.            mov [cpu_sign-OS_BASE], eax
  266.            mov [cpu_info-OS_BASE],  ebx
  267.            mov [cpu_caps-OS_BASE],  edx
  268.            mov [cpu_caps+4-OS_BASE],ecx
  269.            shr eax, 8
  270.            and eax, 0x0f
  271.            ret
  272. endp
  273.  
  274.