begin working on LBA to CHS conversion in assembly
This commit is contained in:
parent
cadf502366
commit
c5498690c6
4 changed files with 77 additions and 5 deletions
2
Makefile
2
Makefile
|
|
@ -102,7 +102,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o obj/util.o obj/test_disk_target.o
|
MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o obj/util.o obj/test_disk_target.o obj/test_disk_read.o
|
||||||
|
|
||||||
mbr_test: $(MBR_TEST_OBJ) $(DISK)
|
mbr_test: $(MBR_TEST_OBJ) $(DISK)
|
||||||
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ entry:
|
||||||
.bootloader:
|
.bootloader:
|
||||||
call serial_init
|
call serial_init
|
||||||
|
|
||||||
mov $0x01, %al # disk 1
|
mov $73728, %eax
|
||||||
call test_disk_params
|
call lba_to_chs
|
||||||
.halt:
|
.halt:
|
||||||
jmp .halt
|
jmp .halt
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,72 @@
|
||||||
.section .text
|
.section .text
|
||||||
.code16
|
.code16
|
||||||
|
|
||||||
|
.globl lba_to_chs
|
||||||
.globl test_disk_read
|
.globl test_disk_read
|
||||||
|
|
||||||
|
# eax - LBA
|
||||||
|
# dh - head, ch - cylinder low 8 bits, cl - high 2 cylinder bits, 6 low bits is sector
|
||||||
|
lba_to_chs:
|
||||||
|
# we actually gonna need stack frame for that one lol
|
||||||
|
push %bp
|
||||||
|
mov %sp, %bp
|
||||||
|
sub $10, %sp
|
||||||
|
# -4(%bp) dword LBA
|
||||||
|
# -6(%bp) word cylinder
|
||||||
|
# -8(%bp) word head
|
||||||
|
# -10(%bp) word sector
|
||||||
|
mov %eax, -4(%bp) # save LBA
|
||||||
|
|
||||||
|
# chs->head = lba / (conf->num_heads * conf->num_sectors);
|
||||||
|
# (conf->num_heads * conf->num_sectors)
|
||||||
|
movw disk_heads, %ax
|
||||||
|
mulw disk_sectors
|
||||||
|
mov %ax, %bx
|
||||||
|
# lba /
|
||||||
|
xor %dx, %dx
|
||||||
|
mov -4(%bp), %eax
|
||||||
|
div %ebx
|
||||||
|
# ax - head
|
||||||
|
mov %ax, -8(%bp)
|
||||||
|
|
||||||
|
# chs->cylinder = (lba / conf->num_sectors) % conf->num_heads;
|
||||||
|
# (lba / conf->num_sectors)
|
||||||
|
xor %dx, %dx
|
||||||
|
movw disk_sectors, %bx
|
||||||
|
mov -4(%bp), %eax
|
||||||
|
div %ebx
|
||||||
|
# % conf->num_heads
|
||||||
|
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
|
||||||
|
# dx - sector
|
||||||
|
mov %dx, -10(%bp)
|
||||||
|
|
||||||
|
# now lets print C H S values
|
||||||
|
mov -6(%bp), %ax
|
||||||
|
mov $str_cylinder, %si
|
||||||
|
call prints_number
|
||||||
|
|
||||||
|
mov -8(%bp), %ax
|
||||||
|
mov $str_head, %si
|
||||||
|
call prints_number
|
||||||
|
|
||||||
|
mov -10(%bp), %ax
|
||||||
|
mov $str_sector, %si
|
||||||
|
call prints_number
|
||||||
|
|
||||||
|
mov %bp, %sp
|
||||||
|
pop %bp
|
||||||
|
ret
|
||||||
|
|
||||||
# eax - LBA address
|
# eax - LBA address
|
||||||
# cx - number of sectors
|
# cx - number of sectors
|
||||||
# es:di - destination
|
# es:di - destination
|
||||||
|
|
@ -14,11 +78,14 @@ test_disk_read:
|
||||||
test_disk_taste_sector:
|
test_disk_taste_sector:
|
||||||
# test pattern partition - each sector has 32 bit integer in beginning
|
# test pattern partition - each sector has 32 bit integer in beginning
|
||||||
# so we read this integer and output it, it must increment as well as LBA address
|
# so we read this integer and output it, it must increment as well as LBA address
|
||||||
lodsd # load 32 bit into eax
|
mov (%esi), %eax
|
||||||
mov $str_taste, %si
|
mov $str_taste, %si
|
||||||
call prints_number
|
call prints_number
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
|
str_cylinder: .asciz "Cylinder: "
|
||||||
|
str_head: .asciz "Head: "
|
||||||
|
str_sector: .asciz "Sector: "
|
||||||
str_taste: .asciz "Sector test pattern: "
|
str_taste: .asciz "Sector test pattern: "
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
# template file for disk parameters
|
# template file for disk parameters
|
||||||
# this will target disk 1
|
# this will target disk 1
|
||||||
|
|
||||||
|
.globl disk_id
|
||||||
|
.globl disk_heads
|
||||||
|
.globl disk_cylinders
|
||||||
|
.globl disk_sectors
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
disk_id: .word 1
|
disk_id: .word 1
|
||||||
disk_heads: .word 16
|
disk_heads: .word 16
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue