Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                      ;;
  3. ;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
  4. ;;                                                                      ;;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  
  7. os_data        =  os_data_l-gdts    ; GDTs
  8. os_code        =  os_code_l-gdts
  9. int_code       equ  int_code_l-gdts
  10. int_data       equ  int_data_l-gdts
  11. tss0sys        equ  tss0sys_l-gdts
  12. graph_data     equ  3+graph_data_l-gdts
  13. tss0           equ  tss0_l-gdts
  14. app_code       equ  3+app_code_l-gdts
  15. app_data       equ  3+app_data_l-gdts
  16.  
  17.  
  18.  
  19. ; CR0 Flags - Protected mode and Paging
  20.  
  21.         mov ecx, CR0_PE
  22.  
  23. ; Enabling 32 bit protected mode
  24.  
  25.         sidt    [cs:old_ints_h-0x10000]
  26.  
  27.         cli                             ; disable all irqs
  28.         cld
  29.         mov     al,255                  ; mask all irqs
  30.         out     0xa1,al
  31.         out     0x21,al
  32.    l.5: in      al, 0x64                ; Enable A20
  33.         test    al, 2
  34.         jnz     l.5
  35.         mov     al, 0xD1
  36.         out     0x64, al
  37.    l.6: in      al, 0x64
  38.         test    al, 2
  39.         jnz     l.6
  40.         mov     al, 0xDF
  41.         out     0x60, al
  42.    l.7: in      al, 0x64
  43.         test    al, 2
  44.         jnz     l.7
  45.         mov     al, 0xFF
  46.         out     0x64, al
  47.         lgdt    [cs:gdts-0x10000]       ; Load GDT
  48.         mov     eax, cr0                ; Turn on paging // protected mode
  49.         or      eax, ecx
  50.         and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
  51.         mov     cr0, eax
  52.         jmp     $+2
  53. org $+0x10000
  54.         mov     ax,os_data              ; Selector for os
  55.         mov     ds,ax
  56.         mov     es,ax
  57.         mov     fs,ax
  58.         mov     gs,ax
  59.         mov     ss,ax
  60.         mov     esp,0x3ec00             ; Set stack
  61.         jmp     pword os_code:B32       ; jmp to enable 32 bit mode
  62.  
  63. if gdte >= $
  64. error 'GDT overlaps with used code!'
  65. end if
  66.