Chameleon

Chameleon Commit Details

Date:2013-12-02 19:57:38 (5 years 7 months ago)
Author:Jief Luce
Commit:2278
Parents: 2277
Message:Use gtc instead of hlt (to allow ctrl-alt-del) + cleanup verbose code
Changes:
M/branches/Jief/i386/boot0/boot0.s

File differences

branches/Jief/i386/boot0/boot0.s
11
22
33
4
4
55
66
77
......
99
1010
1111
12
12
1313
1414
1515
......
1717
1818
1919
20
20
2121
2222
2323
......
2626
2727
2828
29
29
3030
3131
3232
......
8080
8181
8282
83
83
8484
8585
8686
......
9393
9494
9595
96
96
9797
9898
9999
......
101101
102102
103103
104
104
105105
106106
107107
......
118118
119119
120120
121
121
122122
123123
124124
......
134134
135135
136136
137
137
138138
139139
140140
......
150150
151151
152152
153
153
154154
155155
156156
......
213213
214214
215215
216
216
217217
218218
219219
......
237237
238238
239239
240
241
240
241
242242
243243
244244
......
250250
251251
252252
253
254
255
256253
257254
258255
259256
257
258
260259
261260
262261
......
276275
277276
278277
279
278
280279
281280
282281
......
311310
312311
313312
314
313
315314
316315
317316
......
348347
349348
350349
351
352
350
351
353352
354
353
355354
356355
357356
358
357
359358
360359
361360
......
373372
374373
375374
376
375
377376
378377
379378
380379
381380
382
381
383382
384
385
383
384
386385
387386
388387
389
388
390389
391390
392391
......
406405
407406
408407
409
408
410409
411410
412411
......
451450
452451
453452
454
455
456
453
457454
458
459
460
461
462
463
464
465
466
467
468455
469456
470457
......
502489
503490
504491
505
506
507
508
509
510
511492
512493
513494
......
546527
547528
548529
549
530
550531
551532
552533
......
558539
559540
560541
561
542
562543
563544
564545
......
567548
568549
569550
570
551
571552
572553
573
554
574555
575556
576557
......
637618
638619
639620
640
621
641622
642623
643624
......
647628
648629
649630
631
650632
633
651634
652635
653636
654637
655638
656639
657
658
659640
660641
661
662
663
664
665
666
667
668
669
670
671
672
673642
674643
675644
......
677646
678647
679648
680
649
681650
682651
683652
......
692661
693662
694663
695
696
664
665
697666
698667
699668
; Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
;
; @APPLE_LICENSE_HEADER_START@
;
;
; Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
; Reserved. This file contains Original Code and/or Modifications of
; Original Code as defined in and that are subject to the Apple Public
; except in compliance with the License. Please obtain a copy of the
; License at http://www.apple.com/publicsource and read it before using
; this file.
;
;
; The Original Code and all software distributed under the License are
; distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
; EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
; FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
; License for the specific language governing rights and limitations
; under the License.
;
;
; @APPLE_LICENSE_HEADER_END@
;
; Boot Loader: boot0
; responsibility is to locate the active partition, load the
; partition booter into memory, and jump to the booter's entry point.
; It leaves the boot drive in DL and a pointer to the partition entry in SI.
;
;
; This boot loader must be placed in the Master Boot Record.
;
; In order to coexist with a fdisk partition table (64 bytes), and
kHFSPSignatureEQU 'H+'; HFS+ volume signature
kHFSPCaseSignatureEQU 'HX'; HFS+ volume case-sensitive signature
kFAT32BootCodeOffset EQU 0x5a; offset of boot code in FAT32 boot sector
kBoot1FAT32MagicEQU 'BO'; Magic string to detect our boot1f32 code
kBoot1FAT32MagicEQU 'BO'; Magic string to detect our boot1f32 code
kGPTSignatureLowEQU 'EFI '; GUID Partition Table Header Signature
; in LBA 0 (that is, the first block) precedes the
; GUID Partition Table Header to maintain compatibility
; with existing tools that do not understand GPT partition structures.
; The Protective MBR has the same format as a legacy MBR
; The Protective MBR has the same format as a legacy MBR
; and contains one partition entry with an OSType set to 0xEE
; reserving the entire space used on the disk by the GPT partitions,
; including all headers.
kPartActive EQU 0x80; active flag enabled
kPartInactive EQU 0x00; active flag disabled
kHFSGUID EQU 0x48465300; first 4 bytes of Apple HFS Partition Type GUID.
kAppleGUIDEQU 0xACEC4365; last 4 bytes of Apple type GUIDs.
kAppleGUIDEQU 0xACEC4365; last 4 bytes of Apple type GUIDs.
kEFISystemGUIDEQU 0x3BC93EC9; last 4 bytes of EFI System Partition Type GUID:
; C12A7328-F81F-11D2-BA4B-00A0C93EC93B
; giving the size of the structure.
;
struc part
.bootid resb 1 ; bootable or not
.bootid resb 1 ; bootable or not
.head resb 1 ; starting head, sector, cylinder
.sect resb 1 ;
.cyl resb 1 ;
; Format of GPT Partition Table Header
;
strucgpth
.Signature resb8
.Signature resb8
.Revision resb4
.HeaderSizeresb4
.HeaderCRC32resb4
.PartitionEntryArrayCRC32resb4
endstruc
;
;
; Format of GUID Partition Entry Array
;
strucgpta
SEGMENT .text
ORG kBoot0RelocAddr
;--------------------------------------------------------------------------
; Boot code is loaded at 0:7C00h.
;
mov si, kBoot0LoadAddr ; si <- source
mov di, kBoot0RelocAddr ; di <- destination
cld ; auto-increment SI and/or DI registers
mov cx, kSectorBytes/2 ; copy 256 words
repnz movsw ; repeat string move (word) operation
mov cx, kSectorBytes ; copy 512 bytes
repnz movsb ; repeat string move (word) operation
;
; Code relocated, jump to start_reloc in relocated location.
;
start_reloc:
PrintChar('8')
PrintChar('>')
;
; Since this code may not always reside in the MBR, always start by
; loading the MBR to kMBRBuffer and LBA1 to kGPTBuffer.
;
PrintChar('0')
PrintChar('>')
xor eax, eax
mov [my_lba], eax; store LBA sector 0 for read_lba function
; LogString(boot_error_str)
hang:
hlt
call getc
jmp hang
mov [my_lba], eax; save starting LBA for read_lba function
mov cx, [si + gpth.NumberOfPartitionEntries]; number of GUID Partition Array entries
mov bx, [si + gpth.SizeOfPartitionEntry]; size of GUID Partition Array entry
push bx; push size of GUID Partition entry
;
%if VERBOSE
LogString(gpt_str)
%endif
PrintChar('P')
PrintChar('P')
mov dh, 1 ; partition number to give to boot1h
.gpt_loop:
;PrintChar('1')
mov eax, [si + gpta.PartitionTypeGUID + kGUIDLastDwordOffs]
cmpeax, kAppleGUID; check current GUID Partition for Apple's GUID type
je.gpt_ok
;
mov eax, [si + gpta.StartingLBA]; load boot sector from StartingLBA
mov [my_lba], eax
mov [my_lba], eax
call loadBootSector
jne .gpt_continue; no boot loader signature
%if VERBOSE
;LogString(test_str)
%endif
PrintChar('!')
PrintChar('!')
mov ecx, [si + gpta.StartingLBA]
jmp SHORT initBootLoader
jmp SHORT initBootLoader
.gpt_continue:
add si, bx; advance SI to next partition entry
inc dh
loop .gpt_loop; loop through all partition entries
loop .gpt_loop; loop through all partition entries
.exit:
pop bx
;
loadBootSector:
pusha
mov al, 3
mov bx, kBoot0LoadAddr
call load
ret
initBootLoader:
LogString(done_str)
initBootLoader:
PrintChar('J')
;mov eax,kBoot0LoadAddr
;call print_hex
;mov eax,[kBoot0LoadAddr]
;call print_hex
;push si
;pop eax
;PrintHexEax
;PrintHex(edx)
jmp kBoot0LoadAddr
;--------------------------------------------------------------------------
; It pushes 2 bytes with a smaller opcode than if WORD was used
push BYTE 16 ; offset 0-1, packet size
PrintChar('<')
%if DEBUG
mov eax, ecx
call print_hex
%endif
;
; INT13 Func 42 - Extended Read Sectors
;
popad
ret
;--------------------------------------------------------------------------
; Write a string with 'boot0: ' prefix to the console.
;
;
;log_string:
; pusha
;
;
; pushdi
; movsi, log_title_str
; callprint_string
; callprint_string
;
; popa
;
;
; ret
;--------------------------------------------------------------------------
; Write a string to the console.
;
popad
ret
print_nibble:
and al, 0x0f
add al, '0'
.print_ascii:
call print_char
ret
%endif ;DEBUG
getc:
pusha
mov ah, 0
int 0x16
popa
ret
%endif ;DEBUG
;--------------------------------------------------------------------------
; NULL terminated strings.
;
;log_title_strdb 10, 13, 'boot0: ', 0
;boot_error_str db 'err', 0
%if VERBOSE
gpt_strdb 'GPT', 0
;test_strdb 'test', 0
done_strdb 'done', 0
%endif
;--------------------------------------------------------------------------
; Pad the rest of the 512 byte sized booter with zeroes. The last
; two bytes is the mandatory boot sector signature.
;
; that the 'times' argument is negative.
;
; According to EFI specification, maximum boot code size is 440 bytes
; According to EFI specification, maximum boot code size is 440 bytes
;
;
times 508-($-$$) db 0
dw kChameleonBoot1hSignature
dw kBootSignature
ABSOLUTE 0xE400
;

Archive Download the corresponding diff file

Revision: 2278