Недавно я изучал операционные системы, и в настоящее время я нахожусь в точке чтения секторов с 13h / 0x02.Но когда я запускаю свой код, я получаю следующую ошибку:
Disk read error! 0x0C80
Но проблема нечеткая, и когда я ее ищу, появляется сообщение об ошибке или тип носителя не найден (дискета).Вот соответствующий код:
boot.asm
[org 0x7c00] ; bootloader offset
KERNEL_OFFSET equ 0x1000
mov [BOOT_DRIVE], dl
mov bp, 0x9000 ; set the stack
mov sp, bp
mov bx, MSG_REAL_MODE
call printf ; This will be written after the BIOS messages
call load_kernel
call switch_to_pm
jmp $ ; this will actually never be executed
%include "/boot/printf.asm"
%include "/boot/diskload.asm"
%include "/boot/printhex.asm"
%include "/32bit-functions/gdt.asm"
%include "/32bit-functions/32bit-print.asm"
%include "/32bit-functions/switch.asm"
[bits 16]
load_kernel:
mov bx, MSG_LOAD_KERNEL
call printf
mov dl, [BOOT_DRIVE]
mov dh, 0x01
mov bx, KERNEL_OFFSET
call diskload
ret
[bits 32]
BEGIN_PM:
mov ebx, MSG_PROT_MODE
call print_string_pm
call KERNEL_OFFSET ; Give control to the kernel
jmp $ ; Stay here when the kernel returns control to us (if ever)
BOOT_DRIVE db 0 ; It is a good idea to store it in memory because 'dl' may get
;overwritten
MSG_REAL_MODE db "Started in 16-bit Real Mode", 0
MSG_PROT_MODE db "Landed in 32-bit Protected Mode", 0
MSG_LOAD_KERNEL db "Loading kernel into memory", 0
; bootsector
times 510-($-$$) db 0
dw 0xaa55
diskload.asm
; load 'dh' sectors from drive 'dl' into ES:BX
diskload:
pusha
; reading from disk requires setting specific values in all registers
; so we will overwrite our input parameters from 'dx'. Let's save it
; to the stack for later use.
push dx
mov ch, 0x00 ; ch <- cylinder (0x0 .. 0x3FF, upper 2 bits in 'cl')
; dl <- drive number. Our caller sets it as a parameter and gets it from BIOS
; (0 = floppy, 1 = floppy2, 0x80 = hdd, 0x81 = hdd2)
mov cl, 0x02 ; cl <- sector (0x01 .. 0x11)
mov ah, 0x02 ; ah <- int 0x13 function. 0x02 = 'read'
mov al, dh ; al <- number of sectors to read (0x01 .. 0x80)
; 0x01 is our boot sector, 0x02 is the first 'available' sector
mov dh, 0x00 ; dh <- head number (0x0 .. 0xF)
mov es, bx
; [es:bx] <- pointer to buffer where the data will be stored
; caller sets it up for us, and it is actually the standard location for int 13h
int 0x13 ; BIOS interrupt
jc disk_error ; if error (stored in the carry bit)
pop dx
cmp al, dh ; BIOS also sets 'al' to the # of sectors read. Compare it.
jne sectors_error
popa
ret
disk_error:
mov bx, DISK_ERROR
call printf
call print_nl
mov dh, ah ; ah = error code, dl = disk drive that dropped the error
call printhex ; check out the code at http://stanislavs.org/helppc/int_13-1.html
jmp disk_loop
sectors_error:
mov bx, SECTORS_ERROR
call printf
disk_loop:
jmp $
DISK_ERROR: db "Disk read error", 0
SECTORS_ERROR: db "Incorrect number of sectors read", 0
Я не совсемуверен, что я сделал не так.И я потратил некоторое время на поиск ответа
КОНСОЛЬ