Subversion Repositories Kolibri OS

Rev

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