Subversion Repositories Kolibri OS

Rev

Rev 2014 | Rev 3163 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2047 art_zh 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
431 serge 4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;  BOOTCODE.INC                                                ;;
8
;;                                                              ;;
2047 art_zh 9
;;  Kolibri-A auxiliary 16-bit code,                            ;;
10
;;                        based on bootcode for KolibriOS       ;;
431 serge 11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
593 mikedld 14
$Revision: 2047 $
1 ha 15
 
16
 
17
;==========================================================================
18
;
19
;                           16 BIT FUNCTIONS
20
;
21
;==========================================================================
22
 
23
 
134 diamond 24
boot_read_floppy:
1683 art_zh 25
	push	si
26
	xor	si, si
27
	mov	ah, 2	; read
134 diamond 28
@@:
1683 art_zh 29
	push	ax
30
	int	0x13
31
	pop	ax
32
	jnc	@f
33
	inc	si
34
	cmp	si, 10
1703 art_zh 35
	jnb	$
134 diamond 36
@@:
1683 art_zh 37
	pop	si
38
	ret
134 diamond 39
 
1703 art_zh 40
sayerr_plain:
41
sayerr:
42
	jmp	$
43
 
44
 
795 shurf 45
; convert abs. sector number (AX) to BIOS T:H:S
46
; sector number = (abs.sector%BPB_SecPerTrk)+1
47
; pre.track number = (abs.sector/BPB_SecPerTrk)
48
; head number = pre.track number%BPB_NumHeads
49
; track number = pre.track number/BPB_NumHeads
50
; Return: cl - sector number
51
;         ch - track number
52
;         dl - drive number (0 = a:)
53
;         dh - head number
54
conv_abs_to_THS:
1683 art_zh 55
	push	bx
56
	mov	bx,word [BPB_SecPerTrk]
57
	xor	dx,dx
58
	div	bx
59
	inc	dx
60
	mov	cl, dl				; cl = sector number
61
	mov	bx,word [BPB_NumHeads]
62
	xor	dx,dx
63
	div	bx
64
	; !!!!!!! ax = track number, dx = head number
65
	mov	ch,al				; ch=track number
66
	xchg	dh,dl				; dh=head number
67
	mov	dl,0				; dl=0 (drive 0 (a:))
68
	pop	bx
69
	retn
795 shurf 70
; needed variables
1683 art_zh 71
BPB_SecPerTrk	dw	0			; sectors per track
72
BPB_NumHeads	dw	0			; number of heads
73
BPB_FATSz16	dw	0			; size of FAT
74
BPB_RootEntCnt	dw	0			; count of root dir. entries
75
BPB_BytsPerSec	dw	0			; bytes per sector
76
BPB_RsvdSecCnt	dw	0			; number of reserved sectors
77
BPB_TotSec16	dw	0			; count of the sectors on the volume
78
BPB_SecPerClus	db	0			; number of sectors per cluster
79
BPB_NumFATs	db	0			; number of FAT tables
80
abs_sector_adj	dw	0			; adjustment to make abs. sector number
81
end_of_FAT	dw	0			; end of FAT table
82
FirstDataSector dw	0			; begin of data
795 shurf 83
 
1 ha 84
;=========================================================================
85
;
86
;                           16 BIT CODE
87
;
88
;=========================================================================
89
 
1683 art_zh 90
include 'bootvesa.inc'		       ;Include source for boot vesa
1 ha 91
 
92
start_of_code:
1683 art_zh 93
	cld
29 halyavin 94
; \begin{diamond}[02.12.2005]
514 diamond 95
; if bootloader sets ax = 'KL', then ds:si points to loader block
1683 art_zh 96
	cmp	ax, 'KL'
97
	jnz	@f
98
	mov	word [cs:cfgmanager.loader_block], si
99
	mov	word [cs:cfgmanager.loader_block+2], ds
29 halyavin 100
@@:
101
; \end{diamond}[02.12.2005]
1 ha 102
 
514 diamond 103
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
104
; (see comment to bx_from_load)
1683 art_zh 105
	cmp	cx, 'HA'
106
	jnz	no_hd_load
107
	cmp	dx,'RD'
108
	jnz	no_hd_load
109
	mov	word [cs:bx_from_load], bx		; {SPraid}[13.03.2007]
488 spraid 110
no_hd_load:
111
 
29 halyavin 112
; set up stack
1683 art_zh 113
	mov	ax, 3000h
114
	mov	ss, ax
115
	mov	sp, 0EC00h
29 halyavin 116
; set up segment registers
1683 art_zh 117
	push	cs
118
	pop	ds
119
	push	cs
120
	pop	es
1 ha 121
 
122
 
1703 art_zh 123
cpugood:
1 ha 124
 
1683 art_zh 125
	push	0
126
	popf
127
	sti
465 serge 128
 
29 halyavin 129
; set up esp
1683 art_zh 130
	movzx	esp, sp
1 ha 131
 
1683 art_zh 132
	push	0
133
	pop	es
134
	and	word [es:0x9031], 0
164 serge 135
; \begin{Mario79}
136
; find HDD IDE DMA PCI device
160 diamond 137
; check for PCI BIOS
1683 art_zh 138
	mov	ax, 0xB101
139
	int	0x1A
140
	jc	.nopci
141
	cmp	edx, 'PCI '
142
	jnz	.nopci
160 diamond 143
; find PCI class code
144
; class 1 = mass storage
145
; subclass 1 = IDE controller
146
; a) class 1, subclass 1, programming interface 0x80
1683 art_zh 147
	mov	ax, 0xB103
148
	mov	ecx, 1*10000h + 1*100h + 0x80
149
	xor	si, si	; device index = 0
150
	int	0x1A
151
	jnc	.found
187 diamond 152
; b) class 1, subclass 1, programming interface 0x8A
1683 art_zh 153
	mov	ax, 0xB103
154
	mov	ecx, 1*10000h + 1*100h + 0x8A
155
	xor	si, si	; device index = 0
156
	int	0x1A
157
	jnc	.found
187 diamond 158
; c) class 1, subclass 1, programming interface 0x85
1683 art_zh 159
	mov	ax, 0xB103
160
	mov	ecx, 1*10000h + 1*100h + 0x85
161
	xor	si, si
162
	int	0x1A
163
	jc	.nopci
160 diamond 164
.found:
165
; get memory base
1683 art_zh 166
	mov	ax, 0xB10A
167
	mov	di, 0x20	; memory base is config register at 0x20
168
	int	0x1A
169
	jc	.nopci
170
	and	cx, 0xFFF0	; clear address decode type
171
	mov	[es:0x9031], cx
160 diamond 172
.nopci:
164 serge 173
; \end{Mario79}
160 diamond 174
 
76 mario79 175
; --------------- APM ---------------------
1683 art_zh 176
	and	word [es:0x9044], 0	; ver = 0.0 (APM not found)
177
	mov	ax, 0x5300
178
	xor	bx, bx
179
	int	0x15
180
	jc	apm_end 		; APM not found
181
	test	cx, 2
182
	jz	apm_end 		; APM 32-bit protected-mode interface not supported
183
	mov	[es:0x9044], ax 	; Save APM Version
184
	mov	[es:0x9046], cx 	; Save APM flags
164 serge 185
 
1683 art_zh 186
	mov	ax, 0x5304		; Disconnect interface
187
	xor	bx, bx
188
	int	0x15
189
	mov	ax, 0x5303		; Connect 32 bit mode interface
190
	xor	bx, bx
191
	int	0x15
465 serge 192
 
1683 art_zh 193
	mov	[es:0x9040], ebx
194
	mov	[es:0x9050], ax
195
	mov	[es:0x9052], cx
196
	mov	[es:0x9054], dx
465 serge 197
 
76 mario79 198
apm_end:
199
 
713 Lrz 200
;CHECK current of code
1683 art_zh 201
	cmp	[cfgmanager.loader_block], -1
202
	jz	noloaderblock
203
	les	bx, [cfgmanager.loader_block]
204
	cmp	byte [es:bx], 1
205
	jnz	sayerr
206
	push	0
207
	pop	es
713 Lrz 208
 
209
noloaderblock:
1 ha 210
; DISPLAY VESA INFORMATION
1683 art_zh 211
	 call	 print_vesa_info
212
	 call	 calc_vmodes_table
213
	 call	 check_first_parm  ;check and enable cursor_pos
1 ha 214
 
29 halyavin 215
; \begin{diamond}[30.11.2005]
216
cfgmanager:
217
; settings:
218
; a) preboot_graph = graphical mode
219
;    preboot_gprobe = probe this mode?
713 Lrz 220
; b) preboot_dma  = use DMA access?
29 halyavin 221
; c) preboot_vrrm = use VRR?
222
; d) preboot_device = from what boot?
713 Lrz 223
 
29 halyavin 224
; determine default settings
1703 art_zh 225
;        mov     [.bSettingsChanged], 0
713 Lrz 226
 
227
;.preboot_gr_end:
1683 art_zh 228
	mov	di, preboot_device
726 diamond 229
; if image in memory is present and [preboot_device] is uninitialized,
230
; set it to use this preloaded image
1683 art_zh 231
	cmp	byte [di], 0
232
	jnz	.preboot_device_inited
233
	cmp	[.loader_block], -1
234
	jz	@f
235
	les	bx, [.loader_block]
236
	test	byte [es:bx+1], 1
237
	jz	@f
238
	mov	byte [di], 3
239
	jmp	.preboot_device_inited
726 diamond 240
@@:
241
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
1683 art_zh 242
	mov	byte [di], 1
726 diamond 243
.preboot_device_inited:
1018 diamond 244
; following 4 lines set variables to 1 if its current value is 0
1683 art_zh 245
	cmp	byte [di+preboot_dma-preboot_device], 1
246
	adc	byte [di+preboot_dma-preboot_device], 0
247
	cmp	byte [di+preboot_biosdisk-preboot_device], 1
248
	adc	byte [di+preboot_biosdisk-preboot_device], 0
713 Lrz 249
 
1703 art_zh 250
;        pop     ax              ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ??
251
	jmp	.continue
2014 art_zh 252
 
143 diamond 253
.loader_block dd -1
29 halyavin 254
.continue:
1683 art_zh 255
	sti
1703 art_zh 256
	jmp	 .load
946 lrz 257
 
29 halyavin 258
.loadc:
1683 art_zh 259
	pop	eax
29 halyavin 260
.cont:
1683 art_zh 261
	push	cs
262
	pop	ds
29 halyavin 263
.load:
1 ha 264
 
265
; ASK GRAPHICS MODE
266
 
1683 art_zh 267
	call	set_vmode
1 ha 268
 
269
; GRAPHICS ACCELERATION
346 diamond 270
; force yes
1683 art_zh 271
	mov	[es:0x901C], byte 1
1 ha 272
 
514 diamond 273
; DMA ACCESS TO HD
1 ha 274
 
1683 art_zh 275
	mov	al, [preboot_dma]
276
	mov	[es:0x901F], al
346 diamond 277
 
1 ha 278
; VRR_M USE
279
 
1683 art_zh 280
	mov	al,[preboot_vrrm]
281
	mov	[es:0x9030], al
282
	mov	[es:0x901E], byte 1
1 ha 283
 
284
; BOOT DEVICE
285
 
1683 art_zh 286
	mov	al, [preboot_device]
287
	dec	al
288
	mov	[boot_dev], al
1 ha 289
 
1103 diamond 290
 
1 ha 291
; SET GRAPHICS
292
 
1683 art_zh 293
	xor	ax, ax
294
	mov	es, ax
164 serge 295
 
1683 art_zh 296
	mov	bx, [es:0x9008] 	; vga & 320x200
297
	mov	ax, 0x4f02		; Vesa
412 serge 298
setgr:
1683 art_zh 299
	int	0x10
300
	test	ah, ah
1703 art_zh 301
	jnz	$
412 serge 302
gmok2:
1683 art_zh 303
	push	ds
304
	pop	es