Subversion Repositories Kolibri OS

Rev

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