Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 465 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                              ;;
  4. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;  Shutdown for Menuet                                         ;;
  8. ;;                                                              ;;
  9. ;;  Distributed under General Public License                    ;;
  10. ;;  See file COPYING for details.                               ;;
  11. ;;  Copyright 2003 Ville Turjanmaa                              ;;
  12. ;;                                                              ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. align 4
  16. pr_mode_exit:
  17.  
  18. ; setup stack
  19.         mov    ax, 0x3000
  20.         mov    ss, ax
  21.         mov    esp, 0x0EC00
  22. ; setup ds
  23.         push    cs
  24.         pop    ds
  25.  
  26.         lidt [old_ints_h]
  27. ;remap IRQs
  28.         mov  al,0x11
  29.         out  0x20,al
  30.         call rdelay
  31.         out  0xA0,al
  32.         call rdelay
  33.  
  34.         mov  al,0x08
  35.         out  0x21,al
  36.         call rdelay
  37.         mov  al,0x70
  38.         out  0xA1,al
  39.         call rdelay
  40.  
  41.         mov  al,0x04
  42.         out  0x21,al
  43.         call rdelay
  44.         mov  al,0x02
  45.         out  0xA1,al
  46.         call rdelay
  47.  
  48.         mov  al,0x01
  49.         out  0x21,al
  50.         call rdelay
  51.         out  0xA1,al
  52.         call rdelay
  53.  
  54.         mov  al,0xB8
  55.         out  0x21,al
  56.         call rdelay
  57.         mov  al,0xBD
  58.         out  0xA1,al
  59.         sti
  60.  
  61. temp_3456:
  62.         xor  ax,ax
  63.         mov  es,ax
  64.         mov  al,byte [es:0x9030]
  65.         cmp  al,1
  66.         jl   nbw
  67.         cmp  al,4
  68.         jle  nbw32
  69.  
  70. nbw:
  71.         in   al,0x60
  72.         call pause_key
  73.         cmp  al,6
  74.         jae  nbw
  75.         mov  bl,al
  76. nbw2:
  77.         in   al,0x60
  78.         call pause_key
  79.         cmp  al,bl
  80.         je   nbw2
  81.         cmp  al,240  ;ax,240
  82.         jne  nbw31
  83.         mov  al,bl
  84.         dec  ax
  85.         jmp  nbw32
  86. nbw31:
  87.         add  bl,128
  88.         cmp  al,bl
  89.         jne  nbw
  90.         sub  al,129
  91.  
  92. nbw32:
  93.  
  94.         dec  ax    ; 1 = write floppy
  95.         js   nbw
  96.         jnz  no_floppy_write
  97.         call floppy_write
  98.         jmp  temp_3456 ;nbw
  99. no_floppy_write:
  100.  
  101.         dec  ax    ; 2 = power off
  102.         jnz  no_apm_off
  103.         call APM_PowerOff
  104.         jmp  $
  105. no_apm_off:
  106.  
  107.         dec  ax    ; 3 = reboot
  108.         jnz  restart_kernel        ; 4 = restart kernel
  109.         push 0x40
  110.         pop  ds
  111.         mov  word[0x0072],0x1234
  112.         jmp  0xF000:0xFFF0
  113.  
  114. pause_key:
  115.         mov cx,100
  116. pause_key_1:
  117.         loop  pause_key_1
  118.         ret
  119.  
  120. rdelay:
  121.         ret
  122.  
  123. floppy_write:   ; write diskette image to physical floppy
  124.  
  125.         cmp  [flm],byte 1
  126.         je   fwwritedone
  127.         mov  [flm],byte 1
  128.  
  129.         xor    ax, ax        ; reset drive
  130.         xor    dx, dx
  131.         int     0x13
  132.  
  133.         mov     cx,0x0001               ; startcyl,startsector
  134.         xor    dx, dx                    ; starthead,drive
  135.         mov    ax, 80*2               ; read no of sect
  136.  
  137. fwwrites:
  138.         push    ax
  139.  
  140.         ; move 1mb+ -> 0:a000
  141.  
  142.          pusha
  143.         mov     si, fwmovedesc
  144.         mov     cx,256*18
  145.         mov     ah,0x87
  146.         push    ds
  147.         pop    es
  148.         int     0x15
  149.         add    dword [fwmovedesc+0x12], 512*18
  150.         popa
  151.  
  152.         xor     si,si
  153.         mov    es,si
  154. fwnewwrite:
  155.         mov     bx,0xa000               ; es:bx -> data area
  156.         mov     ax,0x0300+18            ; read, no of sectors to read
  157.         int     0x13
  158.  
  159.          test    ah, ah
  160.         jz      fwgoodwrite
  161.  
  162.         inc    si
  163.         cmp     si,10
  164.         jnz     fwnewwrite
  165.  
  166. ; can't access diskette - return
  167.         pop    ax
  168.         ret
  169.  
  170. fwgoodwrite:
  171.         inc     dh
  172.         cmp     dh,2
  173.         jnz     fwbb2
  174.         mov     dh,0
  175.         inc     ch
  176. fwbb2:
  177.         pop     ax
  178.         dec     ax
  179.         jnz     fwwrites
  180.         ret
  181.  
  182. APM_PowerOff:
  183.         mov     ax, 5304h
  184.         xor     bx, bx
  185.         int     15h
  186. ;!!!!!!!!!!!!!!!!!!!!!!!!
  187.         mov ax,0x5300
  188.         xor bx,bx
  189.         int 0x15
  190.         push ax
  191.  
  192.         mov ax,0x5301
  193.         xor bx,bx
  194.         int 0x15
  195.  
  196.         mov ax,0x5308
  197.         mov bx,1
  198.         mov cx,bx
  199.         int 0x15
  200.  
  201.         mov ax,0x530E
  202.         xor bx,bx
  203.         pop cx
  204.         int 0x15
  205.  
  206.         mov ax,0x530D
  207.         mov bx,1
  208.         mov cx,bx
  209.         int 0x15
  210.  
  211.         mov ax,0x530F
  212.         mov bx,1
  213.         mov cx,bx
  214.         int 0x15
  215.  
  216.         mov ax,0x5307
  217.         mov bx,1
  218.         mov cx,3
  219.         int 0x15
  220. ;!!!!!!!!!!!!!!!!!!!!!!!!
  221. fwwritedone:
  222.         ret
  223.  
  224. restart_kernel:
  225.  
  226.         mov     ax,0x0003      ; set text mode for screen
  227.         int     0x10
  228.         jmp     0x4000:0000
  229.  
  230. restart_kernel_4000:
  231.         cli
  232.  
  233.         push    ds
  234.         pop    es
  235.         mov    cx, 0x8000
  236.         push    cx
  237.         mov    ds, cx
  238.         xor    si, si
  239.         xor    di, di
  240.         rep    movsw
  241.         push    0x9000
  242.         pop    ds
  243.         push    0x2000
  244.         pop    es
  245.         pop    cx
  246.         rep    movsw
  247.  
  248.         wbinvd  ; write and invalidate cache
  249.  
  250.         mov    al, 00110100b
  251.         out    43h, al
  252.         jcxz    $+2
  253.         mov    al, 0xFF
  254.         out    40h, al
  255.         jcxz    $+2
  256.         out    40h, al
  257.         jcxz    $+2
  258.         sti
  259.  
  260. ; (hint by Black_mirror)
  261. ; We must read data from keyboard port,
  262. ; because there may be situation when previous keyboard interrupt is lost
  263. ; (due to return to real mode and IRQ reprogramming)
  264. ; and next interrupt will not be generated (as keyboard waits for handling)
  265.         in      al, 0x60
  266.  
  267. ; bootloader interface
  268.         push    0x1000
  269.         pop    ds
  270.         mov    si, kernel_restart_bootblock
  271.         mov    ax, 'KL'
  272.         jmp     0x1000:0000
  273.  
  274.  
  275.