implement LBA to CHS conversion in assembly
This commit is contained in:
parent
721cd172c8
commit
c0e1b0efc2
2 changed files with 39 additions and 34 deletions
|
|
@ -36,7 +36,7 @@ entry:
|
||||||
.bootloader:
|
.bootloader:
|
||||||
call serial_init
|
call serial_init
|
||||||
|
|
||||||
mov $73728, %eax
|
mov $2342424, %eax
|
||||||
call lba_to_chs
|
call lba_to_chs
|
||||||
.halt:
|
.halt:
|
||||||
jmp .halt
|
jmp .halt
|
||||||
|
|
|
||||||
|
|
@ -10,56 +10,61 @@ lba_to_chs:
|
||||||
# we actually gonna need stack frame for that one lol
|
# we actually gonna need stack frame for that one lol
|
||||||
push %bp
|
push %bp
|
||||||
mov %sp, %bp
|
mov %sp, %bp
|
||||||
sub $10, %sp
|
sub $12, %sp
|
||||||
# -4(%bp) dword LBA
|
# -4(%bp) dword LBA
|
||||||
# -6(%bp) word cylinder
|
# -6(%bp) word disk_sectors * 2
|
||||||
# -8(%bp) word head
|
# -8(%bp) word cylinder
|
||||||
# -10(%bp) word sector
|
# -10(%bp) word head
|
||||||
mov %eax, -4(%bp) # save LBA
|
# -12(%bp) word sector
|
||||||
|
mov %eax, -4(%bp) # save LBA
|
||||||
|
|
||||||
# chs->head = lba / (conf->num_heads * conf->num_sectors);
|
# chs->head = (lba % (conf->num_sectors * 2)) / conf->num_sectors;
|
||||||
# (conf->num_heads * conf->num_sectors)
|
# (conf->num_sectors * 2)
|
||||||
movw disk_heads, %ax
|
|
||||||
mulw disk_sectors
|
|
||||||
mov %ax, %bx
|
|
||||||
# lba /
|
|
||||||
xor %dx, %dx
|
xor %dx, %dx
|
||||||
mov -4(%bp), %eax
|
movw disk_sectors, %ax
|
||||||
div %ebx
|
mov $2, %bx
|
||||||
|
mul %bx
|
||||||
|
# ax - num_sectors * 2
|
||||||
|
mov %ax, -6(%bp)
|
||||||
|
|
||||||
|
# (lba %
|
||||||
|
mov %ax, %bx # disk_sectors * 2
|
||||||
|
mov -4(%bp), %eax # lba
|
||||||
|
div %ebx # %
|
||||||
|
# edx, as remainder, now must be divided by num_sectors
|
||||||
|
mov %dx, %ax # remainder ain't gonna exceed 16 bit value
|
||||||
|
xor %dx, %dx # always clear god damn EDX it can screw your div/mul!
|
||||||
|
divw disk_sectors
|
||||||
# ax - head
|
# ax - head
|
||||||
|
mov %ax, -10(%bp)
|
||||||
|
|
||||||
|
# chs->cylinder = (lba / (conf->num_sectors * 2));
|
||||||
|
mov -4(%bp), %eax # LBA
|
||||||
|
mov -6(%bp), %bx # disk_sectors * 2
|
||||||
|
div %ebx # /
|
||||||
|
# ax - cylinder
|
||||||
mov %ax, -8(%bp)
|
mov %ax, -8(%bp)
|
||||||
|
|
||||||
# chs->cylinder = (lba / conf->num_sectors) % conf->num_heads;
|
# chs->sector = (lba % conf->num_sectors + 1);
|
||||||
# (lba / conf->num_sectors)
|
mov -4(%bp), %eax # LBA
|
||||||
xor %dx, %dx
|
|
||||||
movw disk_sectors, %bx
|
movw disk_sectors, %bx
|
||||||
mov -4(%bp), %eax
|
|
||||||
div %ebx
|
div %ebx
|
||||||
# % conf->num_heads
|
# dx - sector, but needs +1
|
||||||
xor %dx, %dx
|
|
||||||
divw disk_heads
|
|
||||||
# dx, as remainder, now has cylinder
|
|
||||||
mov %dx, -6(%bp)
|
|
||||||
|
|
||||||
# chs->sector = (lba % conf->num_sectors) + 1;
|
|
||||||
xor %dx, %dx
|
|
||||||
mov -4(%bp), %eax
|
|
||||||
divw disk_sectors
|
|
||||||
# dx now has sector num, but we need to increment it
|
|
||||||
inc %dx
|
inc %dx
|
||||||
# dx - sector
|
mov %dx, -12(%bp)
|
||||||
mov %dx, -10(%bp)
|
|
||||||
|
xor %eax, %eax # flush eax because it loves to screw up itoa
|
||||||
|
|
||||||
# now lets print C H S values
|
# now lets print C H S values
|
||||||
mov -6(%bp), %ax
|
mov -8(%bp), %ax
|
||||||
mov $str_cylinder, %si
|
mov $str_cylinder, %si
|
||||||
call prints_number
|
call prints_number
|
||||||
|
|
||||||
mov -8(%bp), %ax
|
mov -10(%bp), %ax
|
||||||
mov $str_head, %si
|
mov $str_head, %si
|
||||||
call prints_number
|
call prints_number
|
||||||
|
|
||||||
mov -10(%bp), %ax
|
mov -12(%bp), %ax
|
||||||
mov $str_sector, %si
|
mov $str_sector, %si
|
||||||
call prints_number
|
call prints_number
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue