Subversion Repositories Kolibri OS

Rev

Rev 795 | Rev 925 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 795 Rev 816
Line 9... Line 9...
9
;;  KolibriOS 16-bit loader,                                    ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
10
;;                        based on bootcode for MenuetOS        ;;
10
;;                        based on bootcode for MenuetOS        ;;
11
;;                                                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 13... Line 13...
13
 
13
 
Line 14... Line 14...
14
$Revision: 795 $
14
$Revision: 816 $
15
 
15
 
16
 
16
 
Line 123... Line 123...
123
        xchg    dh,dl                           ; dh=head number
123
        xchg    dh,dl                           ; dh=head number
124
        mov     dl,0                            ; dl=0 (drive 0 (a:))
124
        mov     dl,0                            ; dl=0 (drive 0 (a:))
125
        pop     bx
125
        pop     bx
126
        retn
126
        retn
127
; needed variables
127
; needed variables
128
BPB_SecPerTrk	dw	0			; sectors per track
128
BPB_SecPerTrk   dw      0                       ; sectors per track
129
BPB_NumHeads	dw	0			; number of heads
129
BPB_NumHeads    dw      0                       ; number of heads
130
BPB_FATSz16	dw	0			; size of FAT
130
BPB_FATSz16     dw      0                       ; size of FAT
131
BPB_RootEntCnt	dw	0			; count of root dir. entries
131
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
132
BPB_BytsPerSec	dw	0			; bytes per sector
132
BPB_BytsPerSec  dw      0                       ; bytes per sector
133
BPB_RsvdSecCnt	dw	0			; number of reserved sectors
133
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
134
BPB_TotSec16	dw	0			; count of the sectors on the volume
134
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
135
BPB_SecPerClus	db	0			; number of sectors per cluster
135
BPB_SecPerClus  db      0                       ; number of sectors per cluster
136
BPB_NumFATs	db	0			; number of FAT tables
136
BPB_NumFATs     db      0                       ; number of FAT tables
137
abs_sector_adj	dw	0			; adjustment to make abs. sector number
137
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
138
end_of_FAT	dw	0			; end of FAT table
138
end_of_FAT      dw      0                       ; end of FAT table
139
FirstDataSector	dw	0			; begin of data
139
FirstDataSector dw      0                       ; begin of data
Line 140... Line 140...
140
 
140
 
141
;=========================================================================
141
;=========================================================================
142
;
142
;
143
;                           16 BIT CODE
143
;                           16 BIT CODE
Line 558... Line 558...
558
        call    clear_vmodes_table             ;clear vmodes_table
558
        call    clear_vmodes_table             ;clear vmodes_table
559
        jmp    .printcfg
559
        jmp    .printcfg
560
.change_a:
560
.change_a:
561
.loops:
561
.loops:
562
        call    draw_vmodes_table
562
        call    draw_vmodes_table
563
 
-
 
-
 
563
        _setcursor 25,0         ; out of screen
564
        xor     ax,ax
564
        xor     ax,ax
565
        int     0x16
565
        int     0x16
566
;        call    clear_table_cursor             ;clear current position of cursor
566
;        call    clear_table_cursor             ;clear current position of cursor
Line 567... Line 567...
567
 
567
 
Line 624... Line 624...
624
        pop     bp
624
        pop     bp
625
        push    word [es:bp]
625
        push    word [es:bp]
626
        pop     word [x_save]
626
        pop     word [x_save]
627
        push    word [es:bp+2]
627
        push    word [es:bp+2]
628
        pop     word [y_save]
628
        pop     word [y_save]
629
	push	word [es:bp+6]
629
        push    word [es:bp+6]
630
        pop     word [number_vm]
630
        pop     word [number_vm]
631
        mov     word [preboot_graph],bp           ;save choose
631
        mov     word [preboot_graph],bp           ;save choose
Line 632... Line 632...
632
        
632
        
Line 845... Line 845...
845
 
845
 
846
; TODO: !!!! read only first sector and set variables !!!!!
846
; TODO: !!!! read only first sector and set variables !!!!!
847
; ...
847
; ...
Line 848... Line 848...
848
; TODO: !!! then read flippy image track by track
848
; TODO: !!! then read flippy image track by track
849
        
849
        
850
	mov     cx, 0x0001      ; startcyl,startsector
850
        mov     cx, 0x0001      ; startcyl,startsector
851
.a1:
851
.a1:
852
        push    cx dx
852
        push    cx dx
853
        mov     al, 18
853
        mov     al, 18
Line 888... Line 888...
888
; no - read only used sectors from floppy
888
; no - read only used sectors from floppy
889
; now load floppy image to memory
889
; now load floppy image to memory
890
; at first load boot sector and first FAT table
890
; at first load boot sector and first FAT table
Line 891... Line 891...
891
 
891
 
892
; read only first sector and fill variables
892
; read only first sector and fill variables
893
	mov	cx, 0x0001	; first logical sector
893
        mov     cx, 0x0001      ; first logical sector
894
	xor	dx, dx		; head = 0, drive = 0 (a:)
894
        xor     dx, dx          ; head = 0, drive = 0 (a:)
895
	mov	al, 1		; read one sector
895
        mov     al, 1           ; read one sector
896
	mov	bx, 0xB000	; es:bx -> data area
896
        mov     bx, 0xB000      ; es:bx -> data area
897
	call	boot_read_floppy
897
        call    boot_read_floppy
898
; fill the necessary parameters to work with a floppy
898
; fill the necessary parameters to work with a floppy
899
	mov	ax, word [es:bx+24]
899
        mov     ax, word [es:bx+24]
900
	mov	word [BPB_SecPerTrk], ax
900
        mov     word [BPB_SecPerTrk], ax
901
	mov	ax, word [es:bx+26]
901
        mov     ax, word [es:bx+26]
902
	mov	word [BPB_NumHeads], ax
902
        mov     word [BPB_NumHeads], ax
903
	mov	ax, word [es:bx+22]
903
        mov     ax, word [es:bx+22]
904
	mov	word [BPB_FATSz16], ax
904
        mov     word [BPB_FATSz16], ax
905
	mov	ax, word [es:bx+17]
905
        mov     ax, word [es:bx+17]
906
	mov	word [BPB_RootEntCnt], ax
906
        mov     word [BPB_RootEntCnt], ax
907
	mov	ax, word [es:bx+11]
907
        mov     ax, word [es:bx+11]
908
	mov	word [BPB_BytsPerSec], ax
908
        mov     word [BPB_BytsPerSec], ax
909
	mov	ax, word [es:bx+14]
909
        mov     ax, word [es:bx+14]
910
	mov	word [BPB_RsvdSecCnt], ax
910
        mov     word [BPB_RsvdSecCnt], ax
911
	mov	ax, word [es:bx+19]
911
        mov     ax, word [es:bx+19]
912
	mov	word [BPB_TotSec16], ax
912
        mov     word [BPB_TotSec16], ax
913
	mov	al, byte [es:bx+13]
913
        mov     al, byte [es:bx+13]
914
	mov	byte [BPB_SecPerClus], al
914
        mov     byte [BPB_SecPerClus], al
915
	mov	al, byte [es:bx+16]
915
        mov     al, byte [es:bx+16]
916
	mov	byte [BPB_NumFATs], al
916
        mov     byte [BPB_NumFATs], al
917
; count of clusters in FAT12 ((size_of_FAT*2)/3)
917
; count of clusters in FAT12 ((size_of_FAT*2)/3)
918
	mov	ax, word [BPB_FATSz16]
918
        mov     ax, word [BPB_FATSz16]
919
	mov	cx, word [BPB_BytsPerSec]
919
        mov     cx, word [BPB_BytsPerSec]
920
	xor	dx, dx
920
        xor     dx, dx
921
	mul	cx
921
        mul     cx
922
	shl	ax, 1
922
        shl     ax, 1
923
	mov	cx, 3
923
        mov     cx, 3
924
	div	cx		; now ax - number of clusters in FAT12
924
        div     cx              ; now ax - number of clusters in FAT12
Line 925... Line 925...
925
	mov	word [end_of_FAT], ax
925
        mov     word [end_of_FAT], ax
926
 
926
 
927
; load first FAT table
927
; load first FAT table
928
	mov     cx, 0x0002      ; startcyl,startsector		; TODO!!!!!
928
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
929
        xor     dx, dx          ; starthead,drive
929
        xor     dx, dx          ; starthead,drive
930
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
930
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
931
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
931
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
Line 932... Line 932...
932
        call    boot_read_floppy
932
        call    boot_read_floppy
933
	mov	bx, 0xB000
933
        mov     bx, 0xB000
934
 
934
 
935
; and copy them to extended memory
935
; and copy them to extended memory
936
        mov     si, movedesc
936
        mov     si, movedesc
937
        mov     [si+8*2+3], bh		; from
937
        mov     [si+8*2+3], bh          ; from
938
	
938
        
939
	mov	ax, word [BPB_BytsPerSec]
939
        mov     ax, word [BPB_BytsPerSec]
940
	shr	ax, 1			; words per sector
940
        shr     ax, 1                   ; words per sector
941
	mov	cx, word [BPB_RsvdSecCnt]
941
        mov     cx, word [BPB_RsvdSecCnt]
942
	add	cx, word [BPB_FATSz16]
942
        add     cx, word [BPB_FATSz16]
943
	mul	cx
943
        mul     cx
944
	push	ax			; save to stack count of words in boot+FAT
944
        push    ax                      ; save to stack count of words in boot+FAT
945
	xchg	ax, cx
945
        xchg    ax, cx
946
	
946
        
947
        push    es
947
        push    es
948
        push    ds
948
        push    ds
949
        pop     es
949
        pop     es
950
        mov     ah, 0x87
950
        mov     ah, 0x87
951
        int     0x15
951
        int     0x15
952
	pop	es
952
        pop     es
953
        test    ah, ah
953
        test    ah, ah
954
        jz      @f
954
        jz      @f
955
sayerr_floppy:
955
sayerr_floppy:
956
        mov     dx, 0x3f2
956
        mov     dx, 0x3f2
957
        mov     al, 0
957
        mov     al, 0
958
        out     dx, al
958
        out     dx, al
959
        mov     si, memmovefailed
959
        mov     si, memmovefailed
960
        jmp     sayerr_plain
960
        jmp     sayerr_plain
961
@@:
961
@@:
962
	pop	ax			; restore from stack count of words in boot+FAT
962
        pop     ax                      ; restore from stack count of words in boot+FAT
Line 963... Line 963...
963
	shl	ax, 1			; make bytes count from count of words
963
        shl     ax, 1                   ; make bytes count from count of words
964
	and	eax, 0ffffh
964
        and     eax, 0ffffh
965
        add     dword [si+8*3+2], eax
965
        add     dword [si+8*3+2], eax
966
 
966
 
967
; copy first FAT to second copy
967
; copy first FAT to second copy
968
; TODO: BPB_NumFATs !!!!!
968
; TODO: BPB_NumFATs !!!!!
969
	add	bx, word [BPB_BytsPerSec]	; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
969
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
970
        mov     byte [si+8*2+3], bh	; bx - begin of FAT
970
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
971
	
971
        
972
	mov	ax, word [BPB_BytsPerSec]
972
        mov     ax, word [BPB_BytsPerSec]
Line 973... Line 973...
973
	shr	ax, 1			; words per sector
973
        shr     ax, 1                   ; words per sector
974
	mov	cx, word [BPB_FATSz16]
974
        mov     cx, word [BPB_FATSz16]
975
	mul	cx
975
        mul     cx
976
	mov	cx, ax			; cx - count of words in FAT
976
        mov     cx, ax                  ; cx - count of words in FAT
977
 
977
 
978
        push    es
978
        push    es
979
        push    ds
979
        push    ds
980
        pop     es
980
        pop     es
981
        mov     ah, 0x87
981
        mov     ah, 0x87
982
        int     0x15
982
        int     0x15
983
        pop     es
983
        pop     es
984
        test    ah, ah
984
        test    ah, ah
985
        jnz     sayerr_floppy
985
        jnz     sayerr_floppy
986
	
986
        
987
	mov	ax, cx
987
        mov     ax, cx
988
	shl	ax, 1
988
        shl     ax, 1
989
	and	eax, 0ffffh		; ax - count of bytes in FAT
989
        and     eax, 0ffffh             ; ax - count of bytes in FAT
990
        add     dword [si+8*3+2], eax
990
        add     dword [si+8*3+2], eax
991
	
991
        
992
; reading RootDir
992
; reading RootDir
993
; TODO: BPB_NumFATs
993
; TODO: BPB_NumFATs
994
	add	bx, ax
994
        add     bx, ax
995
	add	bx, 100h
995
        add     bx, 100h
996
	and	bx, 0ff00h			; bx - place in buffer to write RootDir
996
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
997
	push	bx
997
        push    bx
998
 
998
 
999
	mov	bx, word [BPB_BytsPerSec]
999
        mov     bx, word [BPB_BytsPerSec]
1000
	shr	bx, 5				; divide bx by 32
1000
        shr     bx, 5                           ; divide bx by 32
1001
	mov	ax, word [BPB_RootEntCnt]
1001
        mov     ax, word [BPB_RootEntCnt]
1002
	xor	dx, dx
1002
        xor     dx, dx
1003
	div	bx
1003
        div     bx
1004
	push	ax				; ax - count of RootDir sectors
1004
        push    ax                              ; ax - count of RootDir sectors
1005
 
1005
 
1006
	mov	ax, word [BPB_FATSz16]
1006
        mov     ax, word [BPB_FATSz16]
1007
	xor	cx, cx
1007
        xor     cx, cx
1008
	mov	cl, byte [BPB_NumFATs]
1008
        mov     cl, byte [BPB_NumFATs]
1009
	mul	cx
1009
        mul     cx
1010
	add	ax, word [BPB_RsvdSecCnt]	; ax - first sector of RootDir
1010
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1011
 
1011
 
1012
	mov	word [FirstDataSector], ax
1012
        mov     word [FirstDataSector], ax
1013
	pop	bx
1013
        pop     bx
1014
	push	bx
1014
        push    bx
1015
	add	word [FirstDataSector], bx	; Begin of data region of floppy
1015
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1016
	
1016
        
1017
; read RootDir
1017
; read RootDir
1018
	call	conv_abs_to_THS
1018
        call    conv_abs_to_THS
1019
	pop	ax
1019
        pop     ax
1020
	pop	bx				; place in buffer to write
1020
        pop     bx                              ; place in buffer to write
1021
	push	ax
1021
        push    ax
1022
        call    boot_read_floppy		; read RootDir into buffer
1022
        call    boot_read_floppy                ; read RootDir into buffer
1023
; copy RootDir
1023
; copy RootDir
1024
	mov	byte [si+8*2+3], bh		; from buffer
1024
        mov     byte [si+8*2+3], bh             ; from buffer
1025
	pop	ax				; ax = count of RootDir sectors
1025
        pop     ax                              ; ax = count of RootDir sectors
1026
	mov	cx, word [BPB_BytsPerSec]
1026
        mov     cx, word [BPB_BytsPerSec]
1027
	mul	cx
1027
        mul     cx
1028
	shr	ax, 1
1028
        shr     ax, 1
1029
	mov	cx, ax				; count of words to copy
1029
        mov     cx, ax                          ; count of words to copy
1030
	push	es
1030
        push    es
Line 1031... Line 1031...
1031
	push	ds
1031
        push    ds
1032
	pop	es
1032
        pop     es
1033
        mov     ah, 0x87
1033
        mov     ah, 0x87
1034
        int     0x15
1034
        int     0x15
Line 1035... Line 1035...
1035
	pop	es
1035
        pop     es
1036
 
1036
 
1037
	mov	ax, cx
1037
        mov     ax, cx
Line 1038... Line 1038...
1038
	shl	ax, 1
1038
        shl     ax, 1
1039
	and	eax, 0ffffh		; ax - count of bytes in RootDir
1039
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1040
        add     dword [si+8*3+2], eax	; add count of bytes copied
1040
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1041
 
1041
 
1042
; Reading data clusters from floppy
1042
; Reading data clusters from floppy
1043
	mov	byte [si+8*2+3], bh
1043
        mov     byte [si+8*2+3], bh
1044
	push	bx
1044
        push    bx
1045
 
1045
 
1046
	mov	di, 2			; First data cluster
1046
        mov     di, 2                   ; First data cluster
Line 1047... Line 1047...
1047
.read_loop:
1047
.read_loop:
1048
	mov	bx, di
1048
        mov     bx, di
1049
	shr	bx, 1			; bx+di = di*1.5
1049
        shr     bx, 1                   ; bx+di = di*1.5
1050
	jnc	.even
1050
        jnc     .even
1051
	test	word [es:bx+di+0xB200], 0xFFF0	; TODO: may not be 0xB200 !!!
1051
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1052
	jmp	@f
1052
        jmp     @f
1053
.even:
1053
.even:
1054
	test	word [es:bx+di+0xB200], 0xFFF	; TODO: may not be 0xB200 !!!
1054
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1055
 
1055
 
1056
@@:
1056
@@:
1057
	jz	.skip
1057
        jz      .skip
1058
; read cluster di
1058
; read cluster di
1059
;.read:
1059
;.read:
1060
	;conv cluster di to abs. sector ax
1060
        ;conv cluster di to abs. sector ax
1061
	; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1061
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1062
	mov	ax, di
1062
        mov     ax, di
1063
	sub	ax, 2
1063
        sub     ax, 2
1064
	xor	bx, bx
1064
        xor     bx, bx
1065
	mov	bl, byte [BPB_SecPerClus]
1065
        mov     bl, byte [BPB_SecPerClus]
1066
	mul	bx
1066
        mul     bx
1067
	add	ax, word [FirstDataSector]
1067
        add     ax, word [FirstDataSector]
1068
	call	conv_abs_to_THS
1068
        call    conv_abs_to_THS
1069
	pop	bx
1069
        pop     bx
1070
	push	bx
1070
        push    bx
1071
	mov	al, byte [BPB_SecPerClus]	; number of sectors in cluster
1071
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1072
	call	boot_read_floppy
1072
        call    boot_read_floppy
1073
        push    es
1073
        push    es
1074
        push    ds
1074
        push    ds
1075
        pop     es
1075
        pop     es
1076
        pusha
1076
        pusha
1077
;
1077
;
1078
	mov	ax, word [BPB_BytsPerSec]
1078
        mov     ax, word [BPB_BytsPerSec]
1079
	xor	cx, cx
1079
        xor     cx, cx
1080
	mov	cl, byte [BPB_SecPerClus]
1080
        mov     cl, byte [BPB_SecPerClus]
1081
	mul	cx
1081
        mul     cx
1082
	shr	ax, 1				; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1082
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1083
	mov	cx, ax				; number of words to copy (count words in cluster)
1083
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1084
;
1084
;
1085
	mov     ah, 0x87
1085
        mov     ah, 0x87
1086
        int     0x15				; copy data
1086
        int     0x15                            ; copy data
1087
        test    ah, ah
1087
        test    ah, ah
1088
        popa
1088
        popa
1089
        pop     es
1089
        pop     es
Line 1090... Line 1090...
1090
        jnz     sayerr_floppy
1090
        jnz     sayerr_floppy
1091
; skip cluster di
1091
; skip cluster di
1092
.skip:
1092
.skip:
1093
	mov	ax, word [BPB_BytsPerSec]
1093
        mov     ax, word [BPB_BytsPerSec]
1094
	xor	cx, cx
1094
        xor     cx, cx
1095
	mov	cl, byte [BPB_SecPerClus]
1095
        mov     cl, byte [BPB_SecPerClus]
1096
	mul	cx
1096
        mul     cx
1097
	and	eax, 0ffffh		; ax - count of bytes in cluster
1097
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1098
	add	dword [si+8*3+2], eax
1098
        add     dword [si+8*3+2], eax
1099
 
1099
 
1100
	mov	ax, word [end_of_FAT]	; max cluster number
1100
        mov     ax, word [end_of_FAT]   ; max cluster number
1101
        pusha
1101
        pusha
1102
; draw percentage
1102
; draw percentage
1103
; total clusters: ax
1103
; total clusters: ax
Line 1115... Line 1115...
1115
        mov     [si], ax
1115
        mov     [si], ax
1116
        call    printplain
1116
        call    printplain
1117
@@:
1117
@@:
1118
        popa
1118
        popa
1119
        inc     di
1119
        inc     di
1120
	cmp	di, word [end_of_FAT]	; max number of cluster
1120
        cmp     di, word [end_of_FAT]   ; max number of cluster
1121
        jnz     .read_loop
1121
        jnz     .read_loop
1122
	pop	bx			; clear stack
1122
        pop     bx                      ; clear stack
Line 1123... Line 1123...
1123
 
1123
 
1124
ok_sys_on_floppy:
1124
ok_sys_on_floppy:
1125
        mov     si, backspace2
1125
        mov     si, backspace2
1126
        call    printplain
1126
        call    printplain