hos/lst/stage2.lst

989 lines
55 KiB
Plaintext

1
2 %include "bootdef.inc"
3 <1>
4 <1> %define VERSION "0.1.2" ;HOS version
5 <1>
6 <1> %define BOOT_FAT_SEG 0x07E0 ;right after boot sector
7 <1> %define BOOT_ROOT_SEG 0x0900 ;right after FAT
8 <1> %define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR
9 <1> %define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG
10 <1> %define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at
11 <1> %define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical
12 <1> %define BOOT_RD_ADD 0x200000 ;2mb for ram disk
13 <1>
14 <1> %define BOOT_DATA_SEG 0x9000 ;data gathered by stage2 loader goes here
15 <1>
16 <1> %define BOOT_HASRD 0x0000 ;1
17 <1> %define BOOT_VESA 0x0002 ;2 - 0 for console, otherwise VESA mode
18 <1> %define BOOT_VESA_OEM 0x0004 ;258 - null-terminated OEM identification string
19 <1> %define BOOT_VESA_VBE 0x0106 ;512 - copy of VESA VBEInfoBlock
20 <1> %define BOOT_VESA_INFO 0x0306 ;256 - copy of VESA ModeInfoBlock for selected mode
21 <1> %define BOOT_MEMENTRIES 0x040A ;4 - dword = number of memmap entries
22 <1> %define BOOT_MEMMAP 0x2000 ;? - memory map information
23 <1>
24 <1>
25 <1>
26 <1> %define BOOT_DRIVE 0x7C24 ;1 - boot drive
27 <1>
28 <1>
29
30 %define VESA_MODEINFO_SEG 0x0120
31 %define VESA_MODELIST_SEG 0x0140
32 %define GOOD_MODELIST_SEG 0x0160
33
34 [bits 16]
35
36 org BOOT_STAGE2_ADD
37
38
39 ;k now read root directory
40 00000000 BB0009 mov bx, BOOT_ROOT_SEG
41 00000003 8EDB mov ds, bx
42 00000005 31F6 xor si, si ;k now ds:si points to beginning of root directory
43 00000007 8EC6 mov es, si
44 00000009 B9E000 mov cx, 224 ;max root entries
45 loop_compare:
46 0000000C BF[FD07] mov di, kernel
47 0000000F 51 push cx
48 00000010 56 push si ;save pointer to root dir entry
49 00000011 B90B00 mov cx, 11
50 loop_name:
51 00000014 A6 cmpsb
52 00000015 E1FD loopz loop_name
53 00000017 7505 jnz goon ;cx didn't get to zero, bad file
54 00000019 5E pop si
55 0000001A 59 pop cx
56 0000001B E90600 jmp found_file ;good file, ds:si points to start of root directory entry
57 goon:
58 0000001E 5E pop si
59 0000001F 59 pop cx
60 00000020 E2EA loop loop_compare
61
62 error:
63 00000022 EBFE jmp $ ;halt! no kernel file found!
64
65 found_file: ;ds:si points to root dir entry of kernel file
66 00000024 31C0 xor ax, ax
67 00000026 8EE8 mov gs, ax
68 00000028 3E8B441A mov ax, [ds:si+26]
69 0000002C BBE007 mov bx, BOOT_FAT_SEG
70 0000002F 8EDB mov ds, bx ;ds points to beginning of FAT
71 00000031 66BF00001000 mov edi, BOOT_KERNEL_ADD
72
73 readkernel_loop:
74 00000037 3DF70F cmp ax, 0xff7
75 0000003A 7F52 jg readkernel_done
76 0000003C 50 push ax
77 0000003D E85C07 call getCHSfromCluster
78 00000040 B80102 mov ax, 0x0201
79 00000043 658A16247C mov dl, [gs:BOOT_DRIVE]
80 00000048 BBC00A mov bx, BOOT_KERNEL_SEG
81 0000004B 8EC3 mov es, bx
82 0000004D 31DB xor bx, bx
83 0000004F CD13 int 0x13
84 00000051 B90001 mov cx, 256
85 00000054 31C0 xor ax, ax
86 00000056 8EC0 mov es, ax
87 00000058 66BE00AC0000 mov esi, BOOT_KERNEL_SEG*16
88 copykernel_loop:
89 0000005E 26678B06 mov ax, [es:esi]
90 00000062 26678907 mov [es:edi], ax
91 00000066 6646 inc esi
92 00000068 6646 inc esi
93 0000006A 6647 inc edi
94 0000006C 6647 inc edi
95 0000006E E2EE loop copykernel_loop
96
97 00000070 58 pop ax ;current logical cluster #
98
99 00000071 89C1 mov cx, ax ;cx=logical cluster
100 00000073 BA0300 mov dx, 3
101 00000076 F7E2 mul dx
102 00000078 D1E8 shr ax, 1 ;ax=logical cluster * 3 / 2
103 0000007A 89C6 mov si, ax
104 0000007C F6C101 test cl, 1 ;is bit0 set?
105 0000007F 7507 jnz odd_cluster
106 even_cluster:
107 00000081 AD lodsw
108 00000082 25FF0F and ax, 0x0fff
109 00000085 E90400 jmp got_cluster
110 odd_cluster:
111 00000088 AD lodsw
112 00000089 C1E804 shr ax, 4
113 got_cluster:
114 0000008C EBA9 jmp readkernel_loop
115
116 ;------------------------------------------------------
117 readkernel_done: ;-------------put more real mode init stuff here!
118 ;----ask to load RD from floppy
119 0000008E B800B8 mov ax, 0xb800
120 00000091 8EC0 mov es, ax
121 00000093 31C0 xor ax, ax
122 00000095 8ED8 mov ds, ax
123 00000097 31FF xor di, di
124 00000099 B9D007 mov cx, 2000
125 0000009C B80007 mov ax, 0x0700
126 cls_loop:
127 0000009F AB stosw
128 000000A0 E2FD loop cls_loop
129
130 000000A2 BAD403 mov dx, 0x3d4 ;move cursor off screen...
131 000000A5 B00E mov al, 0x0e
132 000000A7 EE out dx, al
133 000000A8 42 inc dx
134 000000A9 B0FF mov al, 0xff
135 000000AB EE out dx, al
136 000000AC 4A dec dx
137 000000AD B00F mov al, 0x0f
138 000000AF EE out dx, al
139 000000B0 42 inc dx
140 000000B1 EE out dx, al
141
142 000000B2 31FF xor di, di
143 000000B4 BE[FB05] mov si, txt_welcome
144 000000B7 B41F mov ah, 0x1f
145 000000B9 E83E04 call puts
146
147 000000BC BFA000 mov di, 160
148 000000BF BE[4C06] mov si, txt_rd1
149 000000C2 B407 mov ah, 7
150 000000C4 E83304 call puts
151
152 000000C7 BE[6F06] mov si, txt_rd2
153 000000CA BF4001 mov di, 160*2
154 000000CD E82A04 call puts
155
156 000000D0 BFE001 mov di, 160*3
157 000000D3 BE[9406] mov si, txt_input
158 000000D6 E82104 call puts
159
160 get_rd:
161 000000D9 31C0 xor ax, ax
162 000000DB CD16 int 0x16
163 000000DD 3C31 cmp al, '1'
164 000000DF 7404 jz got_rd
165 000000E1 3C32 cmp al, '2'
166 000000E3 75F4 jnz get_rd
167 got_rd:
168 000000E5 AA stosb
169 000000E6 2C31 sub al, '1'
170 000000E8 1E push ds
171 000000E9 BB0090 mov bx, BOOT_DATA_SEG ;segment for data to send kernel
172 000000EC 8EDB mov ds, bx
173 000000EE 3EA20000 mov [ds:BOOT_HASRD], al
174 000000F2 1F pop ds ;ds=0
175 000000F3 3C00 cmp al, 0 ;dont load rd
176 000000F5 746F jz no_rd
177
178 000000F7 B95000 mov cx, 80
179 000000FA 66BF80820B00 mov edi, 0xb8000+160*4
180 filler_loop:
181 00000100 3E67C707B104 mov word [ds:edi], 0x0400+177
182 00000106 6647 inc edi
183 00000108 6647 inc edi
184 0000010A E2F4 loop filler_loop
185 0000010C B95000 mov cx, 80 ;80 cylinders to read
186 0000010F 31F6 xor si, si
187 00000111 66BF00002000 mov edi, BOOT_RD_ADD ;ram disk address
188 read_cylinder:
189 00000117 51 push cx
190 00000118 BB0001 mov bx, 0x0100
191 0000011B 8EC3 mov es, bx
192 0000011D 31DB xor bx, bx
193 0000011F B82402 mov ax, 0x0224
194 00000122 89F1 mov cx, si
195 00000124 88CD mov ch, cl
196 00000126 B101 mov cl, 1
197 00000128 31D2 xor dx, dx
198 0000012A 658A16247C mov dl, [gs:BOOT_DRIVE]
199 0000012F CD13 int 0x13
200
201 00000131 66BB00800B00 mov ebx, 0xb8000
202 00000137 01F3 add bx, si
203 00000139 D0E3 shl bl, 1
204 0000013B 3E67C78380020000DB- mov word [ds:ebx+160*4], 0x0200+219
205 00000144 02
206
207 00000145 56 push si
208 00000146 66BE00100000 mov esi, 0x1000
209 0000014C B90024 mov cx, 0x2400
210 copydisk_loop:
211 0000014F 3E678B06 mov ax, [ds:esi]
212 00000153 6646 inc esi
213 00000155 6646 inc esi
214 00000157 3E678907 mov [ds:edi], ax
215 0000015B 6647 inc edi
216 0000015D 6647 inc edi
217 0000015F E2EE loop copydisk_loop
218
219 00000161 5E pop si ;what cylinder# we are on...
220 00000162 46 inc si
221 00000163 59 pop cx
222 00000164 E2B1 loop read_cylinder
223
224 ;------------------------------------------------------
225 no_rd:
226 00000166 B80090 mov ax, BOOT_DATA_SEG
227 00000169 8EC0 mov es, ax
228 0000016B BF0020 mov di, BOOT_MEMMAP ;store memmap info in es:di for kernel
229 0000016E 6631D2 xor edx, edx
230 00000171 B80001 mov ax, 0x0100
231 00000174 8ED8 mov ds, ax
232 00000176 6631DB xor ebx, ebx
233 getmemmap_loop:
234 00000179 06 push es
235 0000017A 57 push di
236 0000017B 6652 push edx
237 0000017D B80001 mov ax, 0x0100 ;get memory map
238 00000180 8EC0 mov es, ax
239 00000182 31FF xor di, di
240 00000184 66B820E80000 mov eax, 0x0000E820
241 0000018A 66B914000000 mov ecx, 0x00000014
242 ;mov ebx, 0x00000000
243 00000190 66BA50414D53 mov edx, 0x534D4150 ;'SMAP'
244 00000196 CD15 int 0x15
245 00000198 7239 jc getmemmap_carry
246 0000019A 663D50414D53 cmp eax, 0x534D4150 ;eax should be 'SMAP' on return...
247 000001A0 751A jnz getmemmap_error
248 000001A2 6681FB00000000 cmp ebx, 0
249 000001A9 742A jz getmemmap_done
250
251 000001AB 665A pop edx ;now, copy memmap entry to es:di on the stack
252 000001AD 5F pop di
253 000001AE 07 pop es
254 000001AF 31F6 xor si, si
255 000001B1 B91400 mov cx, 20
256 getmemmap_copymem_loop:
257 000001B4 AC lodsb
258 000001B5 AA stosb
259 000001B6 E2FC loop getmemmap_copymem_loop
260 000001B8 6642 inc edx
261 000001BA EBBD jmp getmemmap_loop
262
263 getmemmap_error:
264 000001BC B800B8 mov ax, 0xb800
265 000001BF 8EC0 mov es, ax
266 000001C1 BF000F mov di, 160*24
267 000001C4 31C0 xor ax, ax
268 000001C6 8ED8 mov ds, ax
269 000001C8 BE[5D07] mov si, txt_memerror
270 000001CB B404 mov ah, 0x04
271 000001CD E82A03 call puts
272 000001D0 F4 hlt
273 000001D1 EBFE jmp $
274
275 getmemmap_carry:
276 000001D3 664A dec edx
277 getmemmap_done:
278 000001D5 665A pop edx
279 000001D7 5F pop di
280 000001D8 07 pop es
281
282 000001D9 31F6 xor si, si
283 000001DB B91400 mov cx, 20
284 getmemmap_done_copymem_loop:
285 000001DE AC lodsb
286 000001DF AA stosb
287 000001E0 E2FC loop getmemmap_done_copymem_loop
288 000001E2 6642 inc edx
289
290 000001E4 BF0A04 mov di, BOOT_MEMENTRIES
291 000001E7 26668915 mov [es:di], edx ;save # of memmap entries for kernel
292
293 ;on to vesa info...
294 000001EB 31C0 xor ax, ax
295 000001ED 8EE8 mov gs, ax
296 000001EF 8ED8 mov ds, ax
297 000001F1 B800B8 mov ax, 0xb800
298 000001F4 8EC0 mov es, ax
299 000001F6 BFA000 mov di, 160
300 000001F9 B98007 mov cx, 2000-80
301 000001FC B80007 mov ax, 0x0700
302 cls_vesa_loop:
303 000001FF AB stosw
304 00000200 E2FD loop cls_vesa_loop
305 00000202 BE[AB06] mov si, txt_vesa
306 00000205 BFA000 mov di, 160*1
307 00000208 B407 mov ah, 7
308 0000020A E8ED02 call puts
309
310 0000020D 57 push di
311 0000020E B80001 mov ax, 0x0100
312 00000211 8EC0 mov es, ax
313 00000213 31FF xor di, di
314 00000215 2666C70532454256 mov dword [es:di], "2EBV"
315 0000021D B8004F mov ax, 0x4F00
316
317 00000220 CD10 int 0x10
318 00000222 5F pop di
319 00000223 3D4F00 cmp ax, 0x004F
320 00000226 741C jz vesa_good
321 00000228 BE[E406] mov si, txt_novesa
322 0000022B B800B8 mov ax, 0xb800
323 0000022E 8EC0 mov es, ax
324 00000230 B407 mov ah, 7
325 00000232 E8C502 call puts
326 00000235 B80090 mov ax, BOOT_DATA_SEG
327 00000238 8ED8 mov ds, ax
328 0000023A 3EC70602000000 mov word [ds:BOOT_VESA], 0
329 00000241 E9B302 jmp vesa_done
330 vesa_good:
331 00000244 B800B8 mov ax, 0xb800
332 00000247 8EC0 mov es, ax
333 00000249 B80001 mov ax, 0x0100
334 0000024C 8ED8 mov ds, ax
335 0000024E 31F6 xor si, si
336 00000250 8B1E0400 mov bx, [4]
337 00000254 88F8 mov al, bh
338 00000256 E85203 call puthex
339 00000259 B02E mov al, '.'
340 0000025B AA stosb
341 0000025C B007 mov al, 7
342 0000025E AA stosb
343 0000025F 88D8 mov al, bl
344 00000261 E84703 call puthex
345 00000264 81C70400 add di, 4
346 00000268 80FF02 cmp bh, 2
347 0000026B 7D1B jge vesa_good2
348 0000026D 31C0 xor ax, ax
349 0000026F 8ED8 mov ds, ax
350 00000271 BE[1007] mov si, txt_vesaold
351 00000274 B407 mov ah, 7
352 00000276 E88102 call puts
353 00000279 B80090 mov ax, BOOT_DATA_SEG
354 0000027C 8ED8 mov ds, ax
355 0000027E 3EC70602000000 mov word [ds:BOOT_VESA], 0
356 00000285 E96F02 jmp vesa_done
357 vesa_good2:
358 00000288 668B1E0600 mov ebx, [6] ;something like 0x00000E60
359 0000028D 668B160E00 mov edx, [14]
360 00000292 89DE mov si, bx
361 00000294 66C1EB10 shr ebx, 16
362 00000298 8EDB mov ds, bx ;ds:si points to null-terminated OEM identification string
363 0000029A B402 mov ah, 2
364 0000029C 56 push si
365 0000029D E85A02 call puts
366 000002A0 5E pop si
367 000002A1 B80090 mov ax, BOOT_DATA_SEG
368 000002A4 8EC0 mov es, ax
369 000002A6 BF0400 mov di, BOOT_VESA_OEM
370 vesa_copyoem:
371 000002A9 AC lodsb
372 000002AA AA stosb
373 000002AB 08C0 or al, al
374 000002AD 75FA jnz vesa_copyoem
375 000002AF B80001 mov ax, 0x0100
376 000002B2 8ED8 mov ds, ax
377 000002B4 31F6 xor si, si
378 000002B6 BF0601 mov di, BOOT_VESA_VBE
379 000002B9 B90002 mov cx, 512
380 vesa_copyvbe:
381 000002BC AC lodsb
382 000002BD AA stosb
383 000002BE E2FC loop vesa_copyvbe
384
385 000002C0 89D6 mov si, dx
386 000002C2 66C1EA10 shr edx, 16
387 000002C6 8EDA mov ds, dx ;ds:si points to video mode list
388 000002C8 B84001 mov ax, VESA_MODELIST_SEG
389 000002CB 8EC0 mov es, ax
390 000002CD 31FF xor di, di
391 vesa_copymodes:
392 000002CF AD lodsw
393 000002D0 AB stosw
394 000002D1 3DFFFF cmp ax, 0xffff
395 000002D4 75F9 jnz vesa_copymodes
396
397 000002D6 B86001 mov ax, GOOD_MODELIST_SEG
398 000002D9 8EC0 mov es, ax
399 000002DB 31FF xor di, di
400 000002DD B90001 mov cx, 256
401 000002E0 B8FFFF mov ax, 0xffff
402 clear_good_mode_list_loop:
403 000002E3 AB stosw
404 000002E4 E2FD loop clear_good_mode_list_loop
405
406 000002E6 B84001 mov ax, VESA_MODELIST_SEG
407 000002E9 8ED8 mov ds, ax
408 000002EB 31F6 xor si, si ;ds:si points to video mode list where we can edit it :)
409 000002ED B86001 mov ax, GOOD_MODELIST_SEG
410 000002F0 8EC0 mov es, ax
411 000002F2 31FF xor di, di
412 000002F4 31D2 xor dx, dx ;dx=what good mode # we are on
413 vesa_readmodeinfo_loop:
414 000002F6 AD lodsw
415 000002F7 3DFFFF cmp ax, 0xffff
416 000002FA 7414 jz vesa_endofmodes
417 000002FC 50 push ax ;save mode#
418 000002FD E85401 call checkmode
419 00000300 3D0000 cmp ax, 0
420 00000303 7403 jz vesa_readmodeinfo_good
421 00000305 58 pop ax
422 00000306 EBEE jmp vesa_readmodeinfo_loop
423 vesa_readmodeinfo_good:
424 00000308 58 pop ax ;restore mode#
425 00000309 AB stosw
426 0000030A E8BA00 call vesa_showmodeinfo
427 0000030D 42 inc dx
428 0000030E EBE6 jmp vesa_readmodeinfo_loop
429
430 vesa_endofmodes: ;here we have a list of good modes at GOOD_MODELIST_SEG:0
431 00000310 31C0 xor ax, ax
432 00000312 8ED8 mov ds, ax
433 00000314 BE[4707] mov si, txt_consolemode
434 00000317 B800B8 mov ax, 0xb800
435 0000031A 8EC0 mov es, ax
436 0000031C BF4001 mov di, 160*2
437 0000031F B407 mov ah, 7
438 00000321 E8D601 call puts
439 00000324 BFE001 mov di, 160*3
440 00000327 89D1 mov cx, dx
441 00000329 B062 mov al, 'b'
442 vesa_displaylabels:
443 0000032B AA stosb
444 0000032C 50 push ax
445 0000032D B007 mov al, 7
446 0000032F AA stosb
447 00000330 B02E mov al, '.'
448 00000332 AA stosb
449 00000333 B007 mov al, 7
450 00000335 AA stosb
451 00000336 58 pop ax
452 00000337 FEC0 inc al
453 00000339 81C79C00 add di, 160-4
454 0000033D E2EC loop vesa_displaylabels ;done drawing screen of VESA choices, now ask for one
455 ;valid options are 'a' through (al-1)
456 0000033F 88C3 mov bl, al
457 00000341 31C0 xor ax, ax
458 00000343 8ED8 mov ds, ax
459 00000345 BF000F mov di, 160*24
460 00000348 BE[9406] mov si, txt_input
461 0000034B B40E mov ah, 14
462 0000034D E8AA01 call puts
463 vesa_getchoice:
464 00000350 31C0 xor ax, ax
465 00000352 CD16 int 0x16
466 00000354 3C61 cmp al, 'a'
467 00000356 7CF8 jl vesa_getchoice
468 00000358 38D8 cmp al, bl
469 0000035A 7DF4 jge vesa_getchoice
470 0000035C AA stosb
471 0000035D 50 push ax
472 0000035E B00E mov al, 14
473 00000360 AA stosb
474 00000361 58 pop ax
475 00000362 30E4 xor ah, ah
476 00000364 2D6100 sub ax, 'a'
477 00000367 3D0000 cmp ax, 0
478 0000036A 744C jz vesa_consolemode_only
479 0000036C 89C1 mov cx, ax ;cx holds good mode# (1=first good vesa mode)
480 0000036E 49 dec cx
481 0000036F B86001 mov ax, GOOD_MODELIST_SEG
482 00000372 8ED8 mov ds, ax
483 00000374 D1E1 shl cx, 1
484 00000376 89CE mov si, cx ;ds:si points to word containing selected mode#
485 00000378 AD lodsw
486 00000379 89C1 mov cx, ax
487 0000037B 89C2 mov dx, ax ;cx and dx hold mode#
488
489 0000037D B82001 mov ax, VESA_MODEINFO_SEG
490 00000380 8EC0 mov es, ax
491 00000382 31FF xor di, di
492 00000384 B8014F mov ax, 0x4F01
493 00000387 CD10 int 0x10
494 00000389 E87A01 call checkvesa
495
496 0000038C B82001 mov ax, VESA_MODEINFO_SEG
497 0000038F 8ED8 mov ds, ax
498 00000391 31F6 xor si, si
499 00000393 B80090 mov ax, BOOT_DATA_SEG
500 00000396 8EC0 mov es, ax
501 00000398 BF0603 mov di, BOOT_VESA_INFO
502 0000039B B90001 mov cx, 256
503 vesa_copymodeinfo_loop:
504 0000039E AC lodsb
505 0000039F AA stosb
506 000003A0 E2FC loop vesa_copymodeinfo_loop ;store ModeInfoBlock for current
507
508 000003A2 2689160200 mov [es:BOOT_VESA], dx ;store mode# for kernel
509
510 ; mov ax, 0xb800
511 ; mov es, ax
512 ; xor di, di
513 ; mov al, dh
514 ; call puthex2
515 ; mov al, dl
516 ; call puthex2
517
518 000003A7 89D3 mov bx, dx
519 000003A9 81CB0040 or bx, 0x4000 ;set "use LFB" bit of mode#
520 000003AD B8024F mov ax, 0x4F02
521 000003B0 CD10 int 0x10 ;switch to graphics mode!!!
522 000003B2 E85101 call checkvesa
523
524 000003B5 E93F01 jmp vesa_done
525
526 vesa_consolemode_only:
527 000003B8 B80090 mov ax, BOOT_DATA_SEG
528 000003BB 8EC0 mov es, ax
529 000003BD 26C70602000000 mov word [es:BOOT_VESA], 0
530
531 000003C4 E93001 jmp vesa_done
532
533 ;------------------------------------------------------
534 vesa_showmodeinfo:
535 000003C7 60 pusha
536 000003C8 06 push es
537 000003C9 1E push ds
538 000003CA B82001 mov ax, VESA_MODEINFO_SEG
539 000003CD 8ED8 mov ds, ax
540 000003CF 31F6 xor si, si
541 000003D1 B800B8 mov ax, 0xb800
542 000003D4 8EC0 mov es, ax
543
544 000003D6 89D1 mov cx, dx
545
546 000003D8 B8A000 mov ax, 160
547 000003DB F7E2 mul dx ;ax=160*mod#
548 000003DD 05E601 add ax, 160*3+6 ;offset first line of modes and room on left for label
549 000003E0 89C7 mov di, ax
550
551 000003E2 3EA11200 mov ax, [ds:18]
552 000003E6 E83901 call console_putDec
553 000003E9 81C70A00 add di, 10
554 000003ED B078 mov al, 'x'
555 000003EF E8B401 call console_putChar
556 000003F2 47 inc di
557 000003F3 47 inc di
558 000003F4 3EA11400 mov ax, [ds:20]
559 000003F8 E82701 call console_putDec
560 000003FB 81C70A00 add di, 10
561 000003FF B078 mov al, 'x'
562 00000401 E8A201 call console_putChar
563 00000404 47 inc di
564 00000405 47 inc di
565 00000406 30E4 xor ah, ah
566 00000408 3EA01900 mov al, [ds:25]
567 0000040C E81301 call console_putDec
568 0000040F 81C70800 add di, 8
569 00000413 3EA00000 mov al, [ds:0]
570 00000417 A880 test al, 0x80
571 00000419 7435 jz vesa_showmodeinfo_done
572 0000041B B04C mov al, 'L'
573 0000041D E88601 call console_putChar
574 00000420 B046 mov al, 'F'
575 00000422 E88101 call console_putChar
576 00000425 B042 mov al, 'B'
577 00000427 E87C01 call console_putChar
578 0000042A 47 inc di
579 0000042B 47 inc di
580 0000042C 3E668B1E2800 mov ebx, [ds:40]
581 00000432 6689D8 mov eax, ebx
582 00000435 66C1E818 shr eax, 24
583 00000439 E89901 call puthex2
584 0000043C 6689D8 mov eax, ebx
585 0000043F 66C1E810 shr eax, 16
586 00000443 E88F01 call puthex2
587 00000446 88F8 mov al, bh
588 00000448 E88A01 call puthex2
589 0000044B 88D8 mov al, bl
590 0000044D E88501 call puthex2
591 vesa_showmodeinfo_done:
592 00000450 1F pop ds
593 00000451 07 pop es
594 00000452 61 popa
595 00000453 C3 ret
596
597 ;------------------------------------------------------
598 checkmode:
599 00000454 53 push bx
600 00000455 51 push cx
601 00000456 52 push dx
602 00000457 06 push es
603 00000458 1E push ds
604 00000459 57 push di
605 0000045A 56 push si
606 0000045B 89C1 mov cx, ax ;cx=modenumber
607 0000045D B82001 mov ax, VESA_MODEINFO_SEG
608 00000460 8EC0 mov es, ax
609 00000462 31FF xor di, di
610 00000464 B8014F mov ax, 0x4F01
611 00000467 CD10 int 0x10
612 00000469 E89A00 call checkvesa
613 0000046C 31FF xor di, di ;es:di -> ModeInfoBlock struc
614 0000046E 268B05 mov ax, [es:di] ;ModeAttributes
615 00000471 A801 test al, 1 ;mode supported
616 00000473 7477 jz vesa_modenogood
617 00000475 A808 test al, 8 ;color mode
618 00000477 7473 jz vesa_modenogood
619 00000479 A810 test al, 0x10 ;graphics mode
620 0000047B 746F jz vesa_modenogood
621 0000047D A880 test al, 0x80 ;Linear Frame Buffer supported
622 0000047F 746B jz vesa_modenogood
623 00000481 268A4519 mov al, [es:di+25] ;BitsPerPixel
624 00000485 3C10 cmp al, 16
625 00000487 7408 jz vesa_bppok
626 00000489 3C18 cmp al, 24
627 0000048B 7404 jz vesa_bppok
628 0000048D 3C20 cmp al, 32
629 0000048F 755B jnz vesa_modenogood
630 vesa_bppok:
631 00000491 268B4512 mov ax, [es:di+18] ;XResolution
632 00000495 268B5D14 mov bx, [es:di+20] ;YResolution
633 00000499 3D8002 cmp ax, 640 ;640x480
634 0000049C 7509 jnz res_goon1
635 0000049E 81FBE001 cmp bx, 480
636 000004A2 7548 jnz vesa_modenogood
637 000004A4 E93B00 jmp vesa_modegood
638 res_goon1:
639 000004A7 3D2003 cmp ax, 800
640 000004AA 7509 jnz res_goon2
641 000004AC 81FB5802 cmp bx, 600
642 000004B0 753A jnz vesa_modenogood
643 000004B2 E92D00 jmp vesa_modegood
644 res_goon2:
645 000004B5 3D0004 cmp ax, 1024
646 000004B8 7509 jnz res_goon3
647 000004BA 81FB0003 cmp bx, 768
648 000004BE 752C jnz vesa_modenogood
649 000004C0 E91F00 jmp vesa_modegood
650 res_goon3:
651 000004C3 3D0005 cmp ax, 1280
652 000004C6 750F jnz res_goon4
653 000004C8 81FB0004 cmp bx, 1024
654 000004CC 7414 jz vesa_modegood
655 000004CE 81FBC003 cmp bx, 960
656 000004D2 740E jz vesa_modegood
657 000004D4 E91500 jmp vesa_modenogood
658 res_goon4:
659 000004D7 3D4006 cmp ax, 1600
660 000004DA 7510 jnz vesa_modenogood
661 000004DC 81FBB004 cmp bx, 1200
662 000004E0 750A jnz vesa_modenogood
663 vesa_modegood:
664 000004E2 5E pop si
665 000004E3 5F pop di
666 000004E4 1F pop ds
667 000004E5 07 pop es
668 000004E6 5A pop dx
669 000004E7 59 pop cx
670 000004E8 5B pop bx
671 000004E9 31C0 xor ax, ax
672 000004EB C3 ret
673 vesa_modenogood:
674 000004EC 5E pop si
675 000004ED 5F pop di
676 000004EE 1F pop ds
677 000004EF 07 pop es
678 000004F0 5A pop dx
679 000004F1 59 pop cx
680 000004F2 5B pop bx
681 000004F3 B8FFFF mov ax, 0xffff
682 000004F6 C3 ret
683
684 ;------------------------------------------------------
685 vesa_done:
686
687 ; xor ax, ax ;wait for keypress...
688 ; int 0x16
689
690 000004F7 E9D902 jmp go_pm
691
692 ;------------------------------------------------------
693 puts:
694 000004FA AC lodsb
695 000004FB 08C0 or al, al
696 000004FD 7406 jz puts_done
697 000004FF AA stosb
698 00000500 88E0 mov al, ah
699 00000502 AA stosb
700 00000503 EBF5 jmp puts
701 puts_done:
702 00000505 C3 ret
703
704 ;------------------------------------------------------
705 checkvesa:
706 00000506 3D4F00 cmp ax, 0x004F
707 00000509 7501 jnz vesaerror
708 0000050B C3 ret
709 vesaerror:
710 0000050C B800B8 mov ax, 0xb800
711 0000050F 8EC0 mov es, ax
712 00000511 31C0 xor ax, ax
713 00000513 8ED8 mov ds, ax
714 00000515 BE[BA06] mov si, txt_vesaerror
715 00000518 BF000F mov di, 160*24
716 0000051B B404 mov ah, 4
717 0000051D E8DAFF call puts
718 00000520 FA cli
719 00000521 F4 hlt
720
721 ;-------Function console_putDec
722 ;input:
723 ; AX = number to display
724 ;output:
725 ; number written in decimal to es:di
726 console_putDec:
727 00000522 60 pusha
728 00000523 31D2 xor dx, dx
729 00000525 30FF xor bh, bh ;no characters written yet
730 00000527 B91027 mov cx, 10000
731 0000052A F7F1 div cx ;ax=quotiont, dx=remainder
732 0000052C 053000 add ax, '0'
733 0000052F 3D3000 cmp ax, '0'
734 00000532 7405 je .goon1
735 00000534 E86F00 call console_putChar
736 00000537 B701 mov bh, 1
737
738 .goon1:
739 00000539 89D0 mov ax, dx ;load remainder to ax
740 0000053B 31D2 xor dx, dx
741 0000053D B9E803 mov cx, 1000
742 00000540 F7F1 div cx ;ax=quotiont, dx=remainder
743 00000542 053000 add ax, '0'
744 00000545 3D3000 cmp ax, '0'
745 00000548 7408 je .goon11
746 0000054A E85900 call console_putChar
747 0000054D B701 mov bh, 1
748 0000054F E90800 jmp .goon2
749 .goon11:
750 00000552 80FF00 cmp bh, 0
751 00000555 7403 je .goon2
752 00000557 E84C00 call console_putChar
753
754 .goon2:
755 0000055A 89D0 mov ax, dx ;load remainder to ax
756 0000055C 31D2 xor dx, dx
757 0000055E B96400 mov cx, 100
758 00000561 F7F1 div cx ;ax=quotiont, dx=remainder
759 00000563 053000 add ax, '0'
760 00000566 3D3000 cmp ax, '0'
761 00000569 7408 je .goon21
762 0000056B E83800 call console_putChar
763 0000056E B701 mov bh, 1
764 00000570 E90800 jmp .goon3
765 .goon21:
766 00000573 80FF00 cmp bh, 0
767 00000576 7403 je .goon3
768 00000578 E82B00 call console_putChar
769
770 .goon3:
771 0000057B 89D0 mov ax, dx ;load remainder to ax
772 0000057D 31D2 xor dx, dx
773 0000057F B90A00 mov cx, 10
774 00000582 F7F1 div cx ;ax=quotiont, dx=remainder
775 00000584 053000 add ax, '0'
776 00000587 3D3000 cmp ax, '0'
777 0000058A 7408 je .goon31
778 0000058C E81700 call console_putChar
779 0000058F B701 mov bh, 1
780 00000591 E90800 jmp .goon4
781 .goon31:
782 00000594 80FF00 cmp bh, 0
783 00000597 7403 je .goon4
784 00000599 E80A00 call console_putChar
785 .goon4: ;here dx contains last remainder
786 0000059C 89D0 mov ax, dx
787 0000059E 053000 add ax, '0'
788 000005A1 E80200 call console_putChar
789
790 000005A4 61 popa
791 000005A5 C3 ret
792
793 ;------------------------------------------------------
794 console_putChar:
795 000005A6 AA stosb
796 000005A7 B007 mov al, 7
797 000005A9 AA stosb
798 000005AA C3 ret
799
800 ;------------------------------------------------------
801 puthex:
802 ;es:di points to video memory
803 ;al holds hex value
804
805 000005AB 50 push ax
806 000005AC 88C4 mov ah, al
807 000005AE C1E804 shr ax, 4
808 000005B1 240F and al, 0x0F
809 000005B3 0430 add al, '0'
810 000005B5 3C39 cmp al, '9'
811 000005B7 7E02 jle puthex_goon1
812 000005B9 0407 add al, 'A'-'9'-1
813 puthex_goon1:
814 000005BB 3C30 cmp al, '0'
815 000005BD 7404 jz puthex_skipzero
816 000005BF AA stosb
817 000005C0 B007 mov al, 7
818 000005C2 AA stosb
819 puthex_skipzero:
820 000005C3 58 pop ax
821 000005C4 50 push ax
822 000005C5 240F and al, 0x0F
823 000005C7 0430 add al, '0'
824 000005C9 3C39 cmp al, '9'
825 000005CB 7E02 jle puthex_goon2
826 000005CD 0407 add al, 'A'-'9'-1
827 puthex_goon2:
828 000005CF AA stosb
829 000005D0 B007 mov al, 7
830 000005D2 AA stosb
831 000005D3 58 pop ax
832 000005D4 C3 ret
833
834 ;------------------------------------------------------
835 puthex2:
836 ;es:di points to video memory, always displays 2 characters!
837 ;al holds hex value
838
839 000005D5 50 push ax
840 000005D6 88C4 mov ah, al
841 000005D8 C1E804 shr ax, 4
842 000005DB 240F and al, 0x0F
843 000005DD 0430 add al, '0'
844 000005DF 3C39 cmp al, '9'
845 000005E1 7E02 jle puthex2_goon1
846 000005E3 0407 add al, 'A'-'9'-1
847 puthex2_goon1:
848 000005E5 AA stosb
849 000005E6 B007 mov al, 7
850 000005E8 AA stosb
851 000005E9 58 pop ax
852 000005EA 50 push ax
853 000005EB 240F and al, 0x0F
854 000005ED 0430 add al, '0'
855 000005EF 3C39 cmp al, '9'
856 000005F1 7E02 jle puthex2_goon2
857 000005F3 0407 add al, 'A'-'9'-1
858 puthex2_goon2:
859 000005F5 AA stosb
860 000005F6 B007 mov al, 7
861 000005F8 AA stosb
862 000005F9 58 pop ax
863 000005FA C3 ret
864
865 ;------------------------------------------------------
866 000005FB 202020202020202020- txt_welcome: db " Welcome to HOS v", VERSION, "! ", 0
867 00000604 202020202020202020-
868 0000060D 202020202020202020-
869 00000616 202057656C636F6D65-
870 0000061F 20746F20484F532076-
871 00000628 302E312E3221202020-
872 00000631 202020202020202020-
873 0000063A 202020202020202020-
874 00000643 202020202020202000
875 0000064C 312E20446F206E6F74- txt_rd1: db "1. Do not load an initial ram disk", 0
876 00000655 206C6F616420616E20-
877 0000065E 696E697469616C2072-
878 00000667 616D206469736B00
879 0000066F 322E204C6F61642069- txt_rd2: db "2. Load initial ram disk from floppy", 0
880 00000678 6E697469616C207261-
881 00000681 6D206469736B206672-
882 0000068A 6F6D20666C6F707079-
883 00000693 00
884 00000694 456E74657220796F75- txt_input: db "Enter your selection: ", 0
885 0000069D 722073656C65637469-
886 000006A6 6F6E3A2000
887 000006AB 564553412076657273- txt_vesa: db "VESA version: ", 0
888 000006B4 696F6E3A2000
889 000006BA 564553412066756E63- txt_vesaerror: db "VESA function call error! Halting system!", 0
890 000006C3 74696F6E2063616C6C-
891 000006CC 206572726F72212048-
892 000006D5 616C74696E67207379-
893 000006DE 7374656D2100
894 000006E4 56455341206E6F7420- txt_novesa: db "VESA not found. Starting in console mode...", 0
895 000006ED 666F756E642E205374-
896 000006F6 617274696E6720696E-
897 000006FF 20636F6E736F6C6520-
898 00000708 6D6F64652E2E2E00
899 00000710 564553412076657273- txt_vesaold: db "VESA version 2.0 required. Starting in console mode...", 0
900 00000719 696F6E20322E302072-
901 00000722 657175697265642E20-
902 0000072B 5374617274696E6720-
903 00000734 696E20636F6E736F6C-
904 0000073D 65206D6F64652E2E2E-
905 00000746 00
906 00000747 612E20436F6E736F6C- txt_consolemode: db "a. Console mode only.", 0
907 00000750 65206D6F6465206F6E-
908 00000759 6C792E00
909 0000075D 457874656E64656420- txt_memerror: db "Extended Memory Map information unavailable! Halting system...", 0
910 00000766 4D656D6F7279204D61-
911 0000076F 7020696E666F726D61-
912 00000778 74696F6E20756E6176-
913 00000781 61696C61626C652120-
914 0000078A 48616C74696E672073-
915 00000793 797374656D2E2E2E00
916
917 ;------------------------------------------------------
918 getCHSfromCluster:
919 ;input: ax=lba of sector on floppy (0-2879)
920 0000079C 051F00 add ax, 31 ;convert logical cluster# to lba#
921 0000079F 31D2 xor dx, dx ;lba->chs
922 000007A1 BB1200 mov bx, 18
923 000007A4 F7F3 div bx
924 000007A6 42 inc dx
925 000007A7 88D1 mov cl, dl ;sector# (1-18)
926 000007A9 31D2 xor dx, dx
927 000007AB BB0200 mov bx, 2
928 000007AE F7F3 div bx
929 000007B0 88C5 mov ch, al ;cylinder# (0-79)
930 000007B2 88D6 mov dh, dl ;head# (0-1)
931 000007B4 C3 ret
932
933
934 ;-------------------------------------------------------
935 gdtr:
936 000007B5 1700 dw gdt_end-gdt-1
937 000007B7 [BB070000] dd gdt
938 gdt:
939 000007BB 00000000 dd 0
940 000007BF 00000000 dd 0
941
942 KERNEL_CODE equ $-gdt
943 000007C3 FF db 0xff ;limit 7:0
944 000007C4 FF db 0xff ;limit 15:8
945 000007C5 00 db 0x00 ;base 7:0
946 000007C6 00 db 0x00 ;base 15:8
947 000007C7 00 db 0x00 ;base 23:16
948 000007C8 9A db 0x9a ;access
949 000007C9 CF db 0xcf ;flags / limit 19:16
950 000007CA 00 db 0x00 ;base 31:24
951
952 KERNEL_DATA equ $-gdt
953 000007CB FF db 0xff ;segment 16 = 4gb data
954 000007CC FF db 0xff
955 000007CD 00 db 0x00
956 000007CE 00 db 0x00
957 000007CF 00 db 0x00
958 000007D0 92 db 0x92
959 000007D1 CF db 0xcf ;cf
960 000007D2 00 db 0x00
961
962 gdt_end:
963
964 ;------------------------------------------------------
965 go_pm:
966 000007D3 31C0 xor ax, ax
967 000007D5 8ED8 mov ds, ax
968 000007D7 0F0116[B507] lgdt [gdtr]
969 000007DC FA cli
970 000007DD 0F20C0 mov eax, cr0
971 000007E0 6640 inc eax
972 000007E2 0F22C0 mov cr0, eax
973
974 000007E5 EA[EA07]0800 jmp KERNEL_CODE:pmode
975
976 bits 32
977 pmode:
978 000007EA 66B81000 mov ax, KERNEL_DATA
979 000007EE 8EC0 mov es, ax
980 000007F0 8ED8 mov ds, ax
981 000007F2 8EE0 mov fs, ax
982 000007F4 8EE8 mov gs, ax
983 000007F6 EA000010000800 jmp KERNEL_CODE:BOOT_KERNEL_ADD
984
985 000007FD 4B45524E454C202042- kernel: db "KERNEL BIN", 0
986 00000806 494E00
987
988