1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2011 Return Infinity -- see LICENSE.TXT
6 ; =============================================================================
14 ; Read first sector (MBR) into memory
22 cmp byte [0x0000000000005030], 0x01 ; Did we boot from a MBR drive
23 jne hdd_setup_no_mbr
; If not then we already have the correct sector
25 ; Grab the partition offset value for the first partition
27 mov [fat16_PartitionOffset
], eax
29 ; Read the first sector of the first partition
37 ; Get the values we need to start using fat16
39 mov [fat16_BytesPerSector
], ax ; This will probably be 512
41 mov [fat16_SectorsPerCluster
], al ; This will be 128 or less (Max cluster size is 64KiB)
43 mov [fat16_ReservedSectors
], ax
44 mov [fat16_FatStart
], eax
46 mov [fat16_Fats
], al ; This will probably be 2
48 mov [fat16_RootDirEnts
], ax
50 mov [fat16_SectorsPerFat
], ax
52 ; Find out how many sectors are on the disk
56 jne lessthan65536sectors
59 mov [fat16_TotalSectors
], eax
61 ; Calculate the size of the drive in MiB
63 mov eax, [fat16_TotalSectors
]
65 shr rax
, 11 ; rax = rax * 512 / 1048576
66 mov [hd1_size
], eax ; in mebibytes
68 ; Calculate FAT16 info
71 mov ax, [fat16_SectorsPerFat
]
72 shl ax, 1 ; quick multiply by two
73 add ax, [fat16_ReservedSectors
]
74 mov [fat16_RootStart
], eax
75 mov bx, [fat16_RootDirEnts
]
76 shr ebx, 4 ; bx = (bx * 32) / 512
77 add ebx, eax ; BX now holds the datastart sector number
78 mov [fat16_DataStart
], ebx
83 ; =============================================================================