implement BIOS CHS encoding, but somewhere stack is being fucked up

This commit is contained in:
mykola2312 2024-08-07 18:40:51 +03:00
parent 2a66650ee0
commit c3c1cb4ef3
2 changed files with 43 additions and 23 deletions

View file

@ -36,7 +36,19 @@ entry:
.bootloader: .bootloader:
call serial_init call serial_init
mov $9999999, %eax mov $2048, %eax # LBA
call lba_to_chs mov $1, %cl # number of sectors
mov $test_sector, %di # buffer destination
call test_disk_read
// mov test_sector, %eax
// mov $str_test_pattern, %si
// call prints_number
.halt: .halt:
jmp .halt jmp .halt
.section .rodata
str_test_pattern: .asciz "Test pattern: "
.section .bss
.comm test_sector, 512

View file

@ -56,37 +56,46 @@ lba_to_chs:
xor %eax, %eax # flush eax because it loves to screw up itoa xor %eax, %eax # flush eax because it loves to screw up itoa
# now lets print C H S values # convert to BIOS CHS
# DH - head number
# CH - cylinder number, lower 8 bits
# CL - cylinder number 2 high bits, 6 lower bits is sector count
# head
mov -10(%bp), %dh
# cylinder
mov -8(%bp), %ax mov -8(%bp), %ax
mov $str_cylinder, %si mov %al, %ch # cylinder 8 low port
call prints_number shr $6, %ah # bump low 2 bits to high 2 bits
mov %ah, %cl
mov -10(%bp), %ax # sector
mov $str_head, %si
call prints_number
mov -12(%bp), %ax mov -12(%bp), %ax
mov $str_sector, %si or %al, %cl # "apply" sector 6 bits to CL lower part
call prints_number # we won't waste any byte more for masking, since sector calculation
# must have clamped value to 63 max
mov %bp, %sp mov %bp, %sp
pop %bp pop %bp
ret ret
# eax - LBA address # eax - LBA address
# cx - number of sectors # cl - number of sectors
# es:di - destination # es:di - destination
test_disk_read: test_disk_read:
# here we need to convert LBA into CHS push %cx # we just have to push it since lba_to_chs will overwrite it
ret # convert LBA and encode it in BIOS CHS
call lba_to_chs
# ds:si - sector movb disk_id, %dl
test_disk_taste_sector: or $0x80, %dl
# 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 pop %ax # now it will have number of sectors
mov (%esi), %eax mov $0x02, %ah
mov $str_taste, %si mov %di, %bx
call prints_number int $0x13
# BUG: something funny about stack at this point
.debug: jmp .debug
ret ret
@ -94,4 +103,3 @@ test_disk_taste_sector:
str_cylinder: .asciz "Cylinder: " str_cylinder: .asciz "Cylinder: "
str_head: .asciz "Head: " str_head: .asciz "Head: "
str_sector: .asciz "Sector: " str_sector: .asciz "Sector: "
str_taste: .asciz "Sector test pattern: "