Subversion Repositories Kolibri OS

Rev

Rev 2288 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; Copyright (c) 2008-2009, <Lrz>
  2. ; All rights reserved.
  3. ;
  4. ; Redistribution and use in source and binary forms, with or without
  5. ; modification, are permitted provided that the following conditions are met:
  6. ;       * Redistributions of source code must retain the above copyright
  7. ;       notice, this list of conditions and the following disclaimer.
  8. ;       * Redistributions in binary form must reproduce the above copyright
  9. ;       notice, this list of conditions and the following disclaimer in the
  10. ;       documentation and/or other materials provided with the distribution.
  11. ;       * Neither the name of the <organization> nor the
  12. ;       names of its contributors may be used to endorse or promote products
  13. ;       derived from this software without specific prior written permission.
  14. ;
  15. ; THIS SOFTWARE IS PROVIDED BY Alexey Teplov nickname <Lrz> ''AS IS'' AND ANY
  16. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  19. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. ;*****************************************************************************
  26.  
  27. ;start of the project 13.02.2008 year.
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;Secondary Loader copyright Alexey Teplov nickname <Lrz>
  30. ;if you need log preproc
  31. ;/////////////
  32. ;include 'listing.inc'
  33. ;enable listing
  34. ;////////////
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;start of code:                                                               ;
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. use16
  39.                   org   0x0
  40.         jmp     start
  41. include 'sl_equ.inc'            ; в файле размещены все equ предопределения
  42. include 'boot_st.inc'
  43. include 'debug_msg.inc'         ;here is message from debug
  44. include 'parse_dat.inc'
  45. include 'sl_proc.inc'
  46. include 'parse.inc'
  47. include 'parse_loader.inc'
  48. include 'parse_any.inc'
  49. include 'parse_def_sect.inc'
  50. include 'parse_err.inc'
  51.  
  52. file_data  dw 0x0,ini_data_  ;формат: смещение: сегмент т.к. используется les
  53. size_data  dw 16 ;16 блоков по 4 кб т.е предел до 64 кб
  54. name_ini_f db 'kord/startos.ini',0
  55.  
  56. ;////////////
  57. loader_callback dd ?
  58. load_drive dw ?
  59. load_ft    dw ?
  60. ;Start code
  61.  
  62. start:
  63. ; Save far pointer to callback procedure, ds:si is point
  64.         mov     word [cs:loader_callback], si
  65.         mov     word [cs:loader_callback+2], ds
  66. ; Save type of drive
  67.         mov     word [cs:load_drive], ax
  68. ; Save type of FT
  69.         mov     word [cs:load_ft], bx
  70. ; set up stack
  71.         mov     ax, cs
  72.         mov     ss, ax
  73.         xor     sp, sp
  74. ; set up segment registers
  75.         mov     ds, ax
  76.         mov     es, ax
  77. ; just to be sure: force DF=0, IF=1
  78.         cld
  79.         sti
  80.  
  81. ; set videomode
  82.         mov     ax, 3
  83.         int     0x10
  84.  
  85.         mov     si, version
  86.         call    printplain
  87.         mov     al, '#'
  88.         mov     cx, 80
  89. ;input cx=size al=char будет вывден символ сколько раз указано в cx
  90. @@:
  91.         call    putchar
  92.         loop    @b
  93.  
  94.   if DEBUG
  95.         pushad
  96.         mov     ax, cs
  97.         shl     eax, 4  ; в десятичной системе  адрес сегмента
  98.         mov     cx, 0xa
  99.         mov     di, cseg_msg
  100.         call    decode
  101. ;***************
  102.         mov     si, cseg_msg
  103.         call    printplain
  104.         popad
  105.   end if
  106.  
  107.  
  108.   if DEBUG
  109.         mov     si, stack_msg
  110.         call    printplain
  111.   end if
  112.  
  113. ; Require 586 or higher processor (cpuid and rdtsc,rdmsr/wrmsr commands)
  114. ; install int 6 (#UD) handler
  115.         xor     bx, bx
  116.         mov     ds, bx
  117.         push    word [bx+6*4+2]
  118.         push    word [bx+6*4]
  119.         mov     word [bx+6*4], ud16
  120.         mov     word [bx+6*4+2], cs
  121. ; issue CPUID command
  122.         xor     eax, eax        ; N.B.: will cause #UD before 386
  123.         cpuid                   ; N.B.: will cause #UD before later 486s
  124.         test    eax, eax
  125.         jz      cpubad
  126. ; get processor features
  127.         xor     eax, eax
  128.         inc     ax
  129.         cpuid
  130.         test    dl, 10h         ; CPUID[1].edx[4] - TSC support
  131.         jz      cpubad
  132.         test    dl, 20h         ; CPUID[1].edx[5] - MSR support
  133.         jnz     cpugood
  134.  
  135. ud16:   ; #UD handler, called if processor did not recognize some commands
  136. cpubad:
  137. ; restore int 6 (#UD) handler
  138.         pop     word [6*4]
  139.         pop     word [6*4+2]
  140. ; say error
  141.         push    cs
  142.         pop     ds
  143.         mov     si, badprocessor
  144. sayerr:
  145.         call    printplain
  146.         jmp     $
  147.  
  148. cpugood:
  149. ; restore int 6 (#UD) handler
  150.         pop     dword [6*4]
  151.         push    cs
  152.         pop     ds
  153.  
  154. ; set up esp
  155.         movzx   esp, sp
  156.  
  157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. ; init memory
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160.  
  161.  
  162.  
  163.  
  164. ; Load  startos.ini
  165.         mov     cx, loop_read_startos_file      ;кол-во попыток чтения файла конфигурации startos.ini
  166. align 4
  167. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  168. ;  Load startos.ini                                                           ;
  169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170. load_startos_file:
  171.  
  172.         xor     ax, ax
  173.         mov     di, file_data
  174.         inc     ax        ;function 1 - read file
  175.         push    cx
  176.         call    far dword [loader_callback]
  177.         pop     cx
  178.         push    cs
  179.         push    cs
  180.         pop     ds
  181.         pop     es
  182.  
  183.         test    bx, bx
  184.         jz      check_conf_file
  185.         dec     cx
  186.         jnz     load_startos_file
  187.  
  188. ;SET DEFAULT Not use ini file
  189. error_ini:
  190.         mov     si, error_ini_f1    ;Error: cannot load ini file, buffer is full
  191.         dec     bx
  192.         jz      err_show_ini
  193.         mov     si, error_ini_f2    ;Error: ini file not found
  194.         dec     bx
  195.         jz      err_show_ini
  196.         mov     si, error_ini_f3    ;Error: cannot read ini file
  197.         dec     bx
  198.         jz      err_show_ini
  199.  
  200.         mov     si, error_ini_nf    ;Error: unrecognized error when loading ini file
  201. err_show_ini:
  202.         call    printplain
  203.         mov     si, error_ini_common
  204.         call    printplain
  205. ; wait for keypress
  206.         xor     ax, ax
  207.         int     16h
  208.  
  209. ini_loaded:
  210.  
  211.         jmp     $
  212.  
  213. align 4
  214. check_conf_file:
  215. ;Check config file in current dir
  216.         push    ax      ;save size file
  217.   if DEBUG
  218.         mov     cx, 0x0a
  219.         mov     di, show_decode
  220.         call    decode
  221. ;Show size
  222.         mov     si, show_string
  223.         call    printplain
  224.   end if
  225.  
  226.  
  227. ;Show message
  228.         mov     si, load_ini
  229.         call    printplain
  230.  
  231.         pop     cx      ;restore size file
  232. use_parse               ;parsing startos.ini
  233. ;
  234.         jmp     ini_loaded
  235.  
  236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  237. ;DATA
  238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  239. ; table for move to extended memory (int 15h, ah=87h)
  240. align 4
  241. table_15_87:
  242.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  243.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  244.  
  245.         db      0xff,0xff
  246.         db      0x0,0x10
  247.         db      0x00,0x93,0x0,0x0
  248.  
  249.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  250.  
  251.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  252.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  253.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  254.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  255.  
  256. fat12_buffer:
  257. .BS_jmpBoot             db 0x90,0x90,0x90       ;3 байта   NOP инструкция - ничего не делать
  258. .BS_OEMName             db 'K SyS 64'   ;8 байт
  259. .BPB_BytsPerSec         dw      512     ;кол-во байтов в секторе может быть любое 512 1024 2048 4096 2 байта
  260. .BPB_SecPerClus         db      0x1     ;кол-во секторов в кластере
  261. .BPB_RsvdSecCnt         dw      0x1     ;для FAt12/16 только 1, для FAT32 обычно 32    
  262. .BPB_NumFATs            db      0x1     ;кол-во фат таблиц, на тот случай если будет сброс на дискету образа рам диска
  263. .BPB_RootEntCnt         dw      512     ;для мак совместимости с fat16
  264. .BPB_TotSec16           dw      0x0     ;кл-во секторов
  265. .BPB_Media              db      0xF0
  266. .BPB_FATSz16            dw      0x0
  267. .BPB_SecPerTrk          dw      0x0     ;содержит геометрию диска для RAMFS на как бы без разницы, пока пустое поле, позже внести реальные значения.
  268. .BPB_NumHeads           dw      0x0
  269. .BPB_HiddSec            dd      0x0     ;кол-во скрытых секторов
  270. .BPB_TotSec32           dd      0x0
  271. .BS_DrvNum              db      'R'     ;от слова RAM
  272. .BS_Reserved1           db      0x0
  273. .BS_BootSig             db      0x29
  274. .BS_VolID               db      'RFKS'  
  275. .BS_VolLab              db      'RAM DISK FS'   ;11 символов
  276. .BS_FilSysType          db      'FAT12   '      ;8 символов
  277. ;62 байта структура fat12.
  278. db (512-($-fat12_buffer))dup(0x90)
  279.  
  280.  
  281.  
  282. ;структура для дирректории fat
  283. struc FAT_32_entry ;Byte Directory Entry Structure
  284. {
  285. .DIR_Name       rb      11
  286. .DIR_Attr       db      ?
  287. .DIR_NTRes      db      ?
  288. .DIR_CrtTimeTenth db    ?
  289. .DIR_CrtTime    dw      ?
  290. .DIR_CrtDate    dw      ?
  291. .DIR_LstAccDate dw      ?
  292. .DIR_FstClusHI  dw      ?
  293. .DIR_WrtTime    dw      ?
  294. .DIR_WrtDate    dw      ?
  295. .DIR_FstClusLO  dw      ?
  296. .DIR_FileSize   dd      ?
  297.  
  298.  
  299. }
  300. ;Тут будут распологатсья данные, которые затруднительно распологать в стековой области....
  301. ;;;
  302. ;timer
  303. shot_name_fat   rb      11      ;временный буфер для fat12, в нем храняться имена файлов приведенные к правилам FAT /* вдальнейшем перенести в стэк
  304.  
  305. if DEBUG
  306.                 rb      1       ;нужен для отладки и вывода имени файла после преобразования
  307. dest_name_fat   db      24 dup('_');12
  308. db      0x0
  309. end if
  310.  
  311. value_timeout   rw      1       ;value to timeout
  312. old_timer       rd      1       ;старое значение вектора таймера
  313. start_timer     rd      1       ;значение таймера
  314. timer_          rd      1       ;новое значение вектора таймера т.е. SL
  315. start_stack     rw      1       ;save stack
  316. save_bp_from_timer rw   1       ;save bp from timer
  317.  
  318.