Using int 0x13 to write to disk
Posted: Wed Apr 19, 2017 2:43 pm
When I use BIOS int 0x13 to write to disk, I get an error, unless the sector number is 1 or 2.
I am using VirtualBox and booting from a virtual floppy disk. When I query for the drive parameters, ch=0x4f and cl=0x12; but, when I set cl=0x3 when writing, I get an error and al=1. Am I misinterpreting the results of the query?
This is the complete coe
I am using VirtualBox and booting from a virtual floppy disk. When I query for the drive parameters, ch=0x4f and cl=0x12; but, when I set cl=0x3 when writing, I get an error and al=1. Am I misinterpreting the results of the query?
Code: Select all
// "initialization" code is also included below, but removed here for clarity
// at this point, dl is unchanged from its initial value.
mov $0x08, %ah
int $0x13
PUTC $'c
PRINT_HEX <%ch>
PUTC
PRINT_HEX <%cl>
PRINT_NEWLINE
mov initial_dl, %dl
// test write
mov $0x03, %ah
mov $1, %al
mov $end_of_s1, %bx
mov $0, %ch
mov $0x3, %cl
mov $0x00, %dh
int $0x13
jc is_error
PUTC $'n
PUTC $'o
jmp finish
is_error:
PUTC $'e
PUTC $'r
finish:
PRINT_HEX <%ah>
PUTC
PRINT_HEX <%al>
PRINT_NEWLINE
jmp .
end_of_s1:
.asciz "MESSAGE at end of Stage 1"
This is the complete coe
Code: Select all
.code16
.section .boot
/*******************************************************************
*
* Initial set up (including the stack)
*
******************************************************************/
// disable interrupts
cli
/* Set %cs to 0. (If I understand this correctly, in real
mode, the ljmp instruction sets both the CS (code segment)
register as well as the EIP. $1f is the next label with a
value of "1", which appens to be on the next line. Thus, this
instrucion assures that the CS register is set to the segment
containing the code we are currently running
*/
ljmp $0, $1f
1:
/* Sets %ax to 0. (I'm not sure why we're not using mov.) */
xor %ax, %ax
/* Set all the segment registers to 0, just so we know for sure
what's going on. */
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %bp
mov %ax, %ss
mov %bp, %sp
/* Store the initial dl to load stage 2 later on. */
mov %dl, initial_dl
jmp after_locals
initial_dl: .byte 0
after_locals:
PUTC $'g
PRINT_HEX <%dl>
PRINT_NEWLINE
mov $0x08, %ah
int $0x13
PUTC $'c
PRINT_HEX <%ch>
PUTC
PRINT_HEX <%cl>
PRINT_NEWLINE
mov initial_dl, %dl
// test write
mov $0x03, %ah
mov $1, %al
mov end_of_s1, %bx
mov $0, %ch
mov $0x3, %cl
mov $0x00, %dh
int $0x13
jc is_error
PUTC $'n
PUTC $'o
jmp finish
is_error:
PUTC $'e
PUTC $'r
finish:
PRINT_HEX <%ah>
PUTC
PRINT_HEX <%al>
PRINT_NEWLINE
jmp .
end_of_s1:
.asciz "MESSAGE at end of Stage 1"