Subversion Repositories Kolibri OS

Rev

Rev 5565 | Rev 6242 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;  Shutdown for Menuet                                         ;;
  7. ;;                                                              ;;
  8. ;;  Distributed under General Public License                    ;;
  9. ;;  See file COPYING for details.                               ;;
  10. ;;  Copyright 2003 Ville Turjanmaa                              ;;
  11. ;;                                                              ;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. $Revision: 6240 $
  15.  
  16. use32
  17. become_real:
  18.         xor     ebx, ebx
  19.         xor     edx, edx
  20.         xor     ecx, ecx
  21.         xor     esi, esi
  22.         xor     edi, edi
  23.         xor     ebp, ebp
  24.         cli
  25.         ltr     bx
  26.         lgdt    [realmode_gdt-OS_BASE]
  27.         jmp     8:@f
  28. use16
  29. @@:
  30.         mov     ax, 10h
  31.         mov     ds, ax
  32.         mov     es, ax
  33.         mov     fs, ax
  34.         mov     gs, ax
  35.         mov     ss, ax
  36.         mov     eax, cr0
  37.         and     eax, not 80000001h
  38.         mov     cr0, eax
  39.         jmp     0x1000:pr_mode_exit
  40.  
  41. pr_mode_exit:
  42.  
  43. ; setup stack
  44.         mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
  45.         mov     ss, ax
  46.         mov     esp, TMP_STACK_TOP and 0xFFFF
  47.  
  48. ;setup ds
  49.         push    cs
  50.         pop     ds
  51.  
  52.         lidt    [old_ints_h]
  53. ;remap IRQs
  54.         mov     al, 0x11
  55.         out     0x20, al
  56.         call    rdelay
  57.         out     0xA0, al
  58.         call    rdelay
  59.  
  60.         mov     al, 0x08
  61.         out     0x21, al
  62.         call    rdelay
  63.         mov     al, 0x70
  64.         out     0xA1, al
  65.         call    rdelay
  66.  
  67.         mov     al, 0x04
  68.         out     0x21, al
  69.         call    rdelay
  70.         mov     al, 0x02
  71.         out     0xA1, al
  72.         call    rdelay
  73.  
  74.         mov     al, 0x01
  75.         out     0x21, al
  76.         call    rdelay
  77.         out     0xA1, al
  78.         call    rdelay
  79.  
  80.         mov     al, 0xB8
  81.         out     0x21, al
  82.         call    rdelay
  83.         mov     al, 0xBD
  84.         out     0xA1, al
  85.         sti
  86.  
  87. temp_3456:
  88.         xor     ax, ax
  89.         mov     es, ax
  90.         mov     al, byte [es:0x9030]
  91.         cmp     al, 1
  92.         jl      nbw
  93.         cmp     al, 4
  94.         jle     nbw32
  95.  
  96. nbw:
  97.         in      al, 0x60
  98.         cmp     al, 6
  99.         jae     nbw
  100.         mov     bl, al
  101. nbw2:
  102.         in      al, 0x60
  103.         cmp     al, bl
  104.         je      nbw2
  105.         cmp     al, 240;ax,240
  106.         jne     nbw31
  107.         mov     al, bl
  108.         dec     ax
  109.         jmp     nbw32
  110. nbw31:
  111.         add     bl, 128
  112.         cmp     al, bl
  113.         jne     nbw
  114.         sub     al, 129
  115.  
  116. nbw32:
  117.  
  118.         dec     ax
  119.         dec     ax ; 2 = power off
  120.         jnz     no_apm_off
  121.         call    APM_PowerOff
  122.         jmp     $
  123. no_apm_off:
  124.  
  125. if ~ defined extended_primary_loader ; kernel restarting is not supported
  126.         dec     ax ; 3 = reboot
  127.         jnz     restart_kernel     ; 4 = restart kernel
  128. end if
  129.         push    0x40
  130.         pop     ds
  131.         mov     word[0x0072], 0x1234
  132.         jmp     0xF000:0xFFF0
  133.  
  134.  
  135. rdelay:
  136.         ret
  137.  
  138. APM_PowerOff:
  139.         mov     ax, 5304h
  140.         xor     bx, bx
  141.         int     15h
  142. ;!!!!!!!!!!!!!!!!!!!!!!!!
  143.         mov     ax, 0x5300
  144.         xor     bx, bx
  145.         int     0x15
  146.         push    ax
  147.  
  148.         mov     ax, 0x5301
  149.         xor     bx, bx
  150.         int     0x15
  151.  
  152.         mov     ax, 0x5308
  153.         mov     bx, 1
  154.         mov     cx, bx
  155.         int     0x15
  156.  
  157.         mov     ax, 0x530E
  158.         xor     bx, bx
  159.         pop     cx
  160.         int     0x15
  161.  
  162.         mov     ax, 0x530D
  163.         mov     bx, 1
  164.         mov     cx, bx
  165.         int     0x15
  166.  
  167.         mov     ax, 0x530F
  168.         mov     bx, 1
  169.         mov     cx, bx
  170.         int     0x15
  171.  
  172.         mov     ax, 0x5307
  173.         mov     bx, 1
  174.         mov     cx, 3
  175.         int     0x15
  176. ;!!!!!!!!!!!!!!!!!!!!!!!!
  177.         ret
  178.  
  179. if ~ defined extended_primary_loader
  180. restart_kernel:
  181.  
  182.         mov     ax, 0x0003     ; set text mode for screen
  183.         int     0x10
  184.         jmp     0x5000:0000
  185.  
  186. restart_kernel_5001:
  187.         cli
  188.  
  189.         push    ds
  190.         pop     es
  191.         xor     si, si
  192.         xor     di, di
  193.  
  194.         push    0x7100
  195.         pop     ds
  196.         mov     cx, 0x4000
  197.         rep movsd
  198.  
  199.         push    0x8100
  200.         pop     ds
  201.         push    0x2000
  202.         pop     es
  203.         mov     cx, 0x4000
  204.         rep movsd
  205.  
  206.         push    0x9100
  207.         pop     ds
  208.         push    0x3000
  209.         pop     es
  210.         mov     cx, 0x4000
  211.         rep movsd
  212. xchg bx, bx
  213.         push    0xA100
  214.         pop     ds
  215.         push    0x4000
  216.         pop     es
  217.         mov     cx, 0x800
  218.         rep movsd
  219.  
  220.         wbinvd  ; write and invalidate cache
  221.  
  222.         mov     al, 00110100b
  223.         out     43h, al
  224.         jcxz    $+2
  225.         mov     al, 0xFF
  226.         out     40h, al
  227.         jcxz    $+2
  228.         out     40h, al
  229.         jcxz    $+2
  230.         sti
  231.  
  232. ; (hint by Black_mirror)
  233. ; We must read data from keyboard port,
  234. ; because there may be situation when previous keyboard interrupt is lost
  235. ; (due to return to real mode and IRQ reprogramming)
  236. ; and next interrupt will not be generated (as keyboard waits for handling)
  237.         in      al, 0x60
  238.  
  239. ; bootloader interface
  240.         push    0x1000
  241.         pop     ds
  242.         mov     si, kernel_restart_bootblock
  243.         mov     ax, 'KL'
  244.         jmp     0x1000:0000
  245. end if
  246.  
  247.