Subversion Repositories Kolibri OS

Rev

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