Subversion Repositories Kolibri OS

Rev

Rev 749 | Rev 816 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 749 Rev 795
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: 749 $
14
$Revision: 795 $
15
 
15
 
16
 
16
 
Line 97... Line 97...
97
        jmp     $
97
        jmp     $
98
@@:
98
@@:
99
        pop     si
99
        pop     si
100
        ret
100
        ret
Line -... Line 101...
-
 
101
 
-
 
102
; convert abs. sector number (AX) to BIOS T:H:S
-
 
103
; sector number = (abs.sector%BPB_SecPerTrk)+1
-
 
104
; pre.track number = (abs.sector/BPB_SecPerTrk)
-
 
105
; head number = pre.track number%BPB_NumHeads
-
 
106
; track number = pre.track number/BPB_NumHeads
-
 
107
; Return: cl - sector number
-
 
108
;         ch - track number
-
 
109
;         dl - drive number (0 = a:)
-
 
110
;         dh - head number
-
 
111
conv_abs_to_THS:
-
 
112
        push    bx
-
 
113
        mov     bx,word [BPB_SecPerTrk]
-
 
114
        xor     dx,dx
-
 
115
        div     bx
-
 
116
        inc     dx
-
 
117
        mov     cl, dl                          ; cl = sector number
-
 
118
        mov     bx,word [BPB_NumHeads]
-
 
119
        xor     dx,dx
-
 
120
        div     bx
-
 
121
        ; !!!!!!! ax = track number, dx = head number
-
 
122
        mov     ch,al                           ; ch=track number
-
 
123
        xchg    dh,dl                           ; dh=head number
-
 
124
        mov     dl,0                            ; dl=0 (drive 0 (a:))
-
 
125
        pop     bx
-
 
126
        retn
-
 
127
; needed variables
-
 
128
BPB_SecPerTrk	dw	0			; sectors per track
-
 
129
BPB_NumHeads	dw	0			; number of heads
-
 
130
BPB_FATSz16	dw	0			; size of FAT
-
 
131
BPB_RootEntCnt	dw	0			; count of root dir. entries
-
 
132
BPB_BytsPerSec	dw	0			; bytes per sector
-
 
133
BPB_RsvdSecCnt	dw	0			; number of reserved sectors
-
 
134
BPB_TotSec16	dw	0			; count of the sectors on the volume
-
 
135
BPB_SecPerClus	db	0			; number of sectors per cluster
-
 
136
BPB_NumFATs	db	0			; number of FAT tables
-
 
137
abs_sector_adj	dw	0			; adjustment to make abs. sector number
-
 
138
end_of_FAT	dw	0			; end of FAT table
-
 
139
FirstDataSector	dw	0			; begin of data
101
 
140
 
102
;=========================================================================
141
;=========================================================================
103
;
142
;
104
;                           16 BIT CODE
143
;                           16 BIT CODE
105
;
144
;
Line 801... Line 840...
801
        lds     si, [es:si+26]
840
        lds     si, [es:si+26]
802
        test    byte [ds:si+10], 40h
841
        test    byte [ds:si+10], 40h
803
        pop     ds
842
        pop     ds
804
        jz      .nocd
843
        jz      .nocd
805
; yes - read all floppy by 18 sectors
844
; yes - read all floppy by 18 sectors
-
 
845
 
-
 
846
; TODO: !!!! read only first sector and set variables !!!!!
-
 
847
; ...
-
 
848
; TODO: !!! then read flippy image track by track
-
 
849
        
806
        mov     cx, 0x0001      ; startcyl,startsector
850
	mov     cx, 0x0001      ; startcyl,startsector
807
.a1:
851
.a1:
808
        push    cx dx
852
        push    cx dx
809
        mov     al, 18
853
        mov     al, 18
810
        mov     bx, 0xa000
854
        mov     bx, 0xa000
Line 842... Line 886...
842
        jmp     .a1
886
        jmp     .a1
843
.nocd:
887
.nocd:
844
; no - read only used sectors from floppy
888
; no - read only used sectors from floppy
845
; now load floppy image to memory
889
; now load floppy image to memory
846
; at first load boot sector and first FAT table
890
; at first load boot sector and first FAT table
-
 
891
 
-
 
892
; read only first sector and fill variables
847
        mov     cx, 0x0001      ; startcyl,startsector
893
	mov	cx, 0x0001	; first logical sector
848
        xor     dx, dx          ; starthead,drive
894
	xor	dx, dx		; head = 0, drive = 0 (a:)
849
        mov     al, 1+9         ; no of sectors to read
895
	mov	al, 1		; read one sector
850
        mov     bx, 0xB000      ; es:bx -> data area
896
	mov	bx, 0xB000	; es:bx -> data area
851
        call    boot_read_floppy
897
	call	boot_read_floppy
-
 
898
; fill the necessary parameters to work with a floppy
-
 
899
	mov	ax, word [es:bx+24]
-
 
900
	mov	word [BPB_SecPerTrk], ax
-
 
901
	mov	ax, word [es:bx+26]
-
 
902
	mov	word [BPB_NumHeads], ax
-
 
903
	mov	ax, word [es:bx+22]
-
 
904
	mov	word [BPB_FATSz16], ax
-
 
905
	mov	ax, word [es:bx+17]
-
 
906
	mov	word [BPB_RootEntCnt], ax
-
 
907
	mov	ax, word [es:bx+11]
-
 
908
	mov	word [BPB_BytsPerSec], ax
-
 
909
	mov	ax, word [es:bx+14]
-
 
910
	mov	word [BPB_RsvdSecCnt], ax
-
 
911
	mov	ax, word [es:bx+19]
-
 
912
	mov	word [BPB_TotSec16], ax
-
 
913
	mov	al, byte [es:bx+13]
-
 
914
	mov	byte [BPB_SecPerClus], al
-
 
915
	mov	al, byte [es:bx+16]
-
 
916
	mov	byte [BPB_NumFATs], al
-
 
917
; count of clusters in FAT12 ((size_of_FAT*2)/3)
-
 
918
	mov	ax, word [BPB_FATSz16]
-
 
919
	mov	cx, word [BPB_BytsPerSec]
-
 
920
	xor	dx, dx
-
 
921
	mul	cx
-
 
922
	shl	ax, 1
-
 
923
	mov	cx, 3
-
 
924
	div	cx		; now ax - number of clusters in FAT12
-
 
925
	mov	word [end_of_FAT], ax
-
 
926
 
-
 
927
; load first FAT table
-
 
928
	mov     cx, 0x0002      ; startcyl,startsector		; TODO!!!!!
-
 
929
        xor     dx, dx          ; starthead,drive
-
 
930
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
-
 
931
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
-
 
932
        call    boot_read_floppy
-
 
933
	mov	bx, 0xB000
-
 
934
 
852
; and copy them to extended memory
935
; and copy them to extended memory
853
        mov     si, movedesc
936
        mov     si, movedesc
854
        mov     [si+8*2+3], bh
937
        mov     [si+8*2+3], bh		; from
-
 
938
	
-
 
939
	mov	ax, word [BPB_BytsPerSec]
-
 
940
	shr	ax, 1			; words per sector
-
 
941
	mov	cx, word [BPB_RsvdSecCnt]
-
 
942
	add	cx, word [BPB_FATSz16]
-
 
943
	mul	cx
-
 
944
	push	ax			; save to stack count of words in boot+FAT
-
 
945
	xchg	ax, cx
-
 
946
	
855
        push    es
947
        push    es
856
        push    ds
948
        push    ds
857
        pop     es
949
        pop     es
858
        mov     cx, 256*10
-
 
859
        mov     ah, 0x87
950
        mov     ah, 0x87
860
        int     0x15
951
        int     0x15
-
 
952
	pop	es
861
        test    ah, ah
953
        test    ah, ah
862
        jz      @f
954
        jz      @f
863
sayerr_floppy:
955
sayerr_floppy:
864
        mov     dx, 0x3f2
956
        mov     dx, 0x3f2
865
        mov     al, 0
957
        mov     al, 0
866
        out     dx, al
958
        out     dx, al
867
        mov     si, memmovefailed
959
        mov     si, memmovefailed
868
        jmp     sayerr_plain
960
        jmp     sayerr_plain
869
@@:
961
@@:
-
 
962
	pop	ax			; restore from stack count of words in boot+FAT
-
 
963
	shl	ax, 1			; make bytes count from count of words
-
 
964
	and	eax, 0ffffh
870
        add     dword [si+8*3+2], 512*10
965
        add     dword [si+8*3+2], eax
-
 
966
 
871
; copy FAT to second copy
967
; copy first FAT to second copy
-
 
968
; TODO: BPB_NumFATs !!!!!
-
 
969
	add	bx, word [BPB_BytsPerSec]	; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
872
        mov     byte [si+8*2+3], 0xB2
970
        mov     byte [si+8*2+3], bh	; bx - begin of FAT
-
 
971
	
-
 
972
	mov	ax, word [BPB_BytsPerSec]
-
 
973
	shr	ax, 1			; words per sector
-
 
974
	mov	cx, word [BPB_FATSz16]
-
 
975
	mul	cx
-
 
976
	mov	cx, ax			; cx - count of words in FAT
-
 
977
 
-
 
978
        push    es
-
 
979
        push    ds
873
        mov     cx, 256*9
980
        pop     es
874
        mov     ah, 0x87
981
        mov     ah, 0x87
875
        int     0x15
982
        int     0x15
876
        pop     es
983
        pop     es
877
        test    ah, ah
984
        test    ah, ah
878
        jnz     sayerr_floppy
985
        jnz     sayerr_floppy
-
 
986
	
-
 
987
	mov	ax, cx
-
 
988
	shl	ax, 1
-
 
989
	and	eax, 0ffffh		; ax - count of bytes in FAT
879
        add     dword [si+8*3+2], 512*9
990
        add     dword [si+8*3+2], eax
-
 
991
	
-
 
992
; reading RootDir
-
 
993
; TODO: BPB_NumFATs
-
 
994
	add	bx, ax
-
 
995
	add	bx, 100h
880
; calculate total number of sectors to read
996
	and	bx, 0ff00h			; bx - place in buffer to write RootDir
-
 
997
	push	bx
-
 
998
 
881
        mov     ax, 1+9+14      ; boot+FAT+root
999
	mov	bx, word [BPB_BytsPerSec]
882
        mov     di, 0xB203
1000
	shr	bx, 5				; divide bx by 32
-
 
1001
	mov	ax, word [BPB_RootEntCnt]
883
.calc_loop:
1002
	xor	dx, dx
-
 
1003
	div	bx
884
        test    word [es:di], 0xFFF
1004
	push	ax				; ax - count of RootDir sectors
-
 
1005
 
885
        jz      @f
1006
	mov	ax, word [BPB_FATSz16]
886
        inc     ax
1007
	xor	cx, cx
-
 
1008
	mov	cl, byte [BPB_NumFATs]
-
 
1009
	mul	cx
-
 
1010
	add	ax, word [BPB_RsvdSecCnt]	; ax - first sector of RootDir
887
@@:
1011
 
888
        test    word [es:di+1], 0xFFF0
1012
	mov	word [FirstDataSector], ax
889
        jz      @f
1013
	pop	bx
890
        inc     ax
1014
	push	bx
-
 
1015
	add	word [FirstDataSector], bx	; Begin of data region of floppy
891
@@:
1016
	
892
        add     di, 3
1017
; read RootDir
893
        cmp     di, 0xB200+1440*3
1018
	call	conv_abs_to_THS
-
 
1019
	pop	ax
894
        jb      .calc_loop
1020
	pop	bx				; place in buffer to write
895
        push    ax
1021
	push	ax
896
        mov     bp, 1+9         ; already read sectors
1022
        call    boot_read_floppy		; read RootDir into buffer
897
; now read rest
1023
; copy RootDir
-
 
1024
	mov	byte [si+8*2+3], bh		; from buffer
-
 
1025
	pop	ax				; ax = count of RootDir sectors
-
 
1026
	mov	cx, word [BPB_BytsPerSec]
-
 
1027
	mul	cx
-
 
1028
	shr	ax, 1
-
 
1029
	mov	cx, ax				; count of words to copy
-
 
1030
	push	es
-
 
1031
	push	ds
-
 
1032
	pop	es
898
        mov     byte [si+8*2+3], 0xA0
1033
        mov     ah, 0x87
-
 
1034
        int     0x15
-
 
1035
	pop	es
-
 
1036
 
-
 
1037
	mov	ax, cx
-
 
1038
	shl	ax, 1
899
        mov     di, 2-14        ; absolute sector-31
1039
	and	eax, 0ffffh		; ax - count of bytes in RootDir
900
        mov     cx, 0x0002      ; cylinder=0, sector=2
1040
        add     dword [si+8*3+2], eax	; add count of bytes copied
-
 
1041
 
-
 
1042
; Reading data clusters from floppy
-
 
1043
	mov	byte [si+8*2+3], bh
-
 
1044
	push	bx
-
 
1045
 
901
        mov     dx, 0x0100      ; head=1, disk=0
1046
	mov	di, 2			; First data cluster
902
.read_loop:
1047
.read_loop:
903
; determine whether sector must be read
-
 
904
        cmp     di, 2
-
 
905
        jl      .read
-
 
906
        mov     bx, di
1048
	mov	bx, di
907
        shr     bx, 1
1049
	shr	bx, 1			; bx+di = di*1.5
908
        jnc     .even
1050
	jnc	.even
909
        test    word [es:bx+di+0xB200], 0xFFF0
1051
	test	word [es:bx+di+0xB200], 0xFFF0	; TODO: may not be 0xB200 !!!
910
        jmp     @f
1052
	jmp	@f
911
.even:
1053
.even:
912
        test    word [es:bx+di+0xB200], 0xFFF
1054
	test	word [es:bx+di+0xB200], 0xFFF	; TODO: may not be 0xB200 !!!
-
 
1055
 
913
@@:
1056
@@:
914
        jz      .skip
1057
	jz	.skip
-
 
1058
; read cluster di
915
.read:
1059
;.read:
916
        mov     bx, 0xA000
1060
	;conv cluster di to abs. sector ax
917
        mov     al, 1           ; 1 sector
1061
	; ax = (N-2) * BPB_SecPerClus + FirstDataSector
-
 
1062
	mov	ax, di
-
 
1063
	sub	ax, 2
-
 
1064
	xor	bx, bx
-
 
1065
	mov	bl, byte [BPB_SecPerClus]
-
 
1066
	mul	bx
-
 
1067
	add	ax, word [FirstDataSector]
-
 
1068
	call	conv_abs_to_THS
-
 
1069
	pop	bx
-
 
1070
	push	bx
-
 
1071
	mov	al, byte [BPB_SecPerClus]	; number of sectors in cluster
918
        call    boot_read_floppy
1072
	call	boot_read_floppy
919
        inc     bp
-
 
920
        push    es
1073
        push    es
921
        push    ds
1074
        push    ds
922
        pop     es
1075
        pop     es
923
        pusha
1076
        pusha
-
 
1077
;
-
 
1078
	mov	ax, word [BPB_BytsPerSec]
-
 
1079
	xor	cx, cx
924
        mov     cx, 256
1080
	mov	cl, byte [BPB_SecPerClus]
-
 
1081
	mul	cx
-
 
1082
	shr	ax, 1				; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
-
 
1083
	mov	cx, ax				; number of words to copy (count words in cluster)
-
 
1084
;
925
        mov     ah, 0x87
1085
	mov     ah, 0x87
926
        int     0x15
1086
        int     0x15				; copy data
927
        test    ah, ah
1087
        test    ah, ah
928
        popa
1088
        popa
929
        pop     es
1089
        pop     es
930
        jnz     sayerr_floppy
1090
        jnz     sayerr_floppy
-
 
1091
; skip cluster di
931
.skip:
1092
.skip:
932
        add     dword [si+8*3+2], 512
1093
	mov	ax, word [BPB_BytsPerSec]
933
        inc     cx
1094
	xor	cx, cx
934
        cmp     cl, 19
-
 
935
        jnz     @f
-
 
936
        mov     cl, 1
1095
	mov	cl, byte [BPB_SecPerClus]
937
        inc     dh
1096
	mul	cx
938
        cmp     dh, 2
1097
	and	eax, 0ffffh		; ax - count of bytes in cluster
939
        jnz     @f
-
 
940
        mov     dh, 0
1098
	add	dword [si+8*3+2], eax
941
        inc     ch
-
 
942
@@:
1099
 
943
        pop     ax
-
 
944
        push    ax
1100
	mov	ax, word [end_of_FAT]	; max cluster number
945
        pusha
1101
        pusha
946
; draw percentage
1102
; draw percentage
947
; total sectors: ax
1103
; total clusters: ax
948
; read sectors: bp
1104
; read clusters: di
949
        xchg    ax, bp
1105
	xchg	ax, di
950
        mov     cx, 100
1106
        mov     cx, 100
951
        mul     cx
1107
        mul     cx
952
        div     bp
1108
	div	di
953
        aam
1109
        aam
954
        xchg    al, ah
1110
        xchg    al, ah
955
        add     ax, '00'
1111
        add     ax, '00'
956
        mov     si, pros
1112
        mov     si, pros
957
        cmp     [si], ax
1113
        cmp     [si], ax
Line 959... Line 1115...
959
        mov     [si], ax
1115
        mov     [si], ax
960
        call    printplain
1116
        call    printplain
961
@@:
1117
@@:
962
        popa
1118
        popa
963
        inc     di
1119
        inc     di
964
        cmp     di, 2880-31
1120
	cmp	di, word [end_of_FAT]	; max number of cluster
965
        jnz     .read_loop
1121
        jnz     .read_loop
966
 
-
 
967
;        mov     cx, 0x0001      ; startcyl,startsector
-
 
968
;        xor     dx, dx          ; starthead,drive
-
 
969
;        push    word 80*2               ; read no of sect
-
 
970
;       reads:
-
 
971
;        pusha
-
 
972
;        xor     si,si
-
 
973
;       newread:
-
 
974
;        mov     bx,0xa000               ; es:bx -> data area
-
 
975
;        mov     ax,0x0200+18            ; read, no of sectors to read
-
 
976
;        int     0x13
-
 
977
;        test    ah, ah
-
 
978
;        jz      goodread
-
 
979
;        inc    si
-
 
980
;        cmp     si,10
-
 
981
;        jnz     newread
-
 
982
;        mov     si,badsect-0x10000
-
 
983
;sayerr_plain:
-
 
984
;        call    printplain
-
 
985
;        jmp     $
-
 
986
;       goodread:
-
 
987
;        ; move -> 1mb
-
 
988
;        mov     si,movedesc-0x10000
-
 
989
;        push    es
-
 
990
;        push    ds
-
 
991
;        pop     es
-
 
992
;        mov     cx,256*18
-
 
993
;        mov     ah,0x87
-
 
994
;        int     0x15
-
 
995
;        pop    es
-
 
996
;
-
 
997
;        test    ah,ah                  ; was the move successfull ?
-
 
998
;        je      goodmove
-
 
999
;        mov     dx,0x3f2              ; floppy motor off
-
 
1000
;        mov     al,0
-
 
1001
;        out     dx,al
-
 
1002
;        mov     si,memmovefailed-0x10000
-
 
1003
;        jmp    sayerr_plain
-
 
1004
;      goodmove:
-
 
1005
;
-
 
1006
;    add    dword [movedesc-0x10000+0x18+2], 512*18
-
 
1007
;        popa
-
 
1008
;        inc     dh
-
 
1009
;        cmp     dh,2
-
 
1010
;        jnz     bb2
-
 
1011
;        mov     dh,0
-
 
1012
;        inc     ch
-
 
1013
;        pusha                        ; print prosentage
-
 
1014
;        mov     si,pros-0x10000
-
 
1015
;    shr    ch, 2
-
 
1016
;    mov    al, '5'
-
 
1017
;    test    ch, 1
-
 
1018
;    jnz    @f
-
 
1019
;    mov    al, '0'
-
 
1020
;@@:
-
 
1021
;    mov    [si+1], al
-
 
1022
;    shr    ch, 1
-
 
1023
;    add    ch, '0'
-
 
1024
;    mov    [si], ch
1122
	pop	bx			; clear stack
1025
;        call    printplain
-
 
1026
;        popa
-
 
1027
;       bb2:
-
 
1028
;        pop     ax
-
 
1029
;        dec     ax
-
 
1030
;        push    ax
-
 
1031
;        jnz     reads
-
 
1032
;       readdone:
-
 
1033
;        pop     ax
-
 
Line 1034... Line 1123...
1034
 
1123
 
1035
ok_sys_on_floppy:
1124
ok_sys_on_floppy:
1036
        mov     si, backspace2
1125
        mov     si, backspace2
1037
        call    printplain
1126
        call    printplain