Кто-нибудь знает, что не так с этим кодом? Я использую VirtualBox для запуска этого, и когда он его запускает, он просто рассылает случайные символы, а затем экран очищается черным с курсором в некоторой случайной области. Что не так с тем, как я загрузил второй сектор?
boot.asm
; 16 bit mode to use 2 byte align with 32 bit mode 4 byte aligned and 64 bit mode 8 byte aligned
%define NEW_LINE 0x0D, 0x0A
[BITS 16]
org 0x0000 ;IP= 0x0000, changes what everything is "offset from" to 0
section .text
jmp 0x07c0:start ; missing a - after 0x7c0 because each digit in hex is worth 4 bits
; CS to7c0, IP = start
variables:
align 2
loadstr: db 'Loading Bootloader...', NEW_LINE
align 2
loadstr_len: dw 23
%include "bootloader_modules/vga.asm" ; include BIOS VEGA functions
%include "bootloader_modules/drive.asm" ; include BIOS drive write functions
start:
align 2
mov ax, cs
mov es, ax
mov ds, ax
bios_set_video_mode WIDE_TEXT_MODE
bios_print_string loadstr, loadstr_len, 0, 0, 0, BLACK_COLOR | WHITE_COLOR
bios_read_disk sector_2, HARD_DISK_DRIVE_N, 0, 2, 0, 1
;jmp $
jmp 0x07c0:second_start
zero_fill times 510 - ($-$$) db 0x00
bootloader_signature: dw 0xAA55
second_start:
bios_print_string disk_string, 12, 0, 0, 0, BLACK_COLOR | WHITE_COLOR
jmp $
disk_string: db 'Hello There!',NEW_LINE
;times 512 - ($-second_start) db 0x00
sector_2: times 512 - ($-second_start) db 0x00
vga.asm :
;16_BIT_COLOR_PALLETE
%define BLACK_COLOR 0x000000
%define BLUE_COLOR 0x000001
%define GREEN_COLOR 0x000002
%define CYAN_COLOR 0x000003
%define RED_COLOR 0x000004
%define MAGENTA_COLOR 0x000005
%define BROWN_COLOR 0x000006
%define GREY_COLOR 0x000007
%define DARK_GREY_COLOR 0x000008
%define LIGH_BLUE_COLOR 0x000009
%define LIGHT_GREEN_COLOR 0x00000A
%define LIGHT_CYAN_COLOR 0x00000B
%define LIGHT_RED_COLOR 0x00000C
%define LIGHT_MAGENTA_COLOR 0x00000D
%define YELLOW_COLOR 0x00000E
%define WHITE_COLOR 0x00000F
%define BLACK_COLOR_M 0x000000
%define BLUE_COLOR_M 0x0000A8
%define GREEN_COLOR_M 0x00A800
%define CYAN_COLOR_M 0x00A8A8
%define RED_COLOR_M 0xA80000
%define MAGENTA_COLOR_M 0xA800A8
%define ORANGE_COLOR_M 0xA85400
%define GREY_COLOR_M 0xA8A8A8
%define DARK_GREY_COLOR_M 0x545454
%define LIGH_BLUE_COLOR_M 0x5454FE
%define LIGHT_GREEN_COLOR_M 0x54FE54
%define LIGHT_CYAN_COLOR_M 0x54FEFE
%define BRIGHT_RED_COLOR_M 0xFE5454
%define BRIGHT_MAGENTA_COLOR_M 0xFE54FE
%define YELLOW_COLOR_M 0xFEFE54
%define WHITE_COLOR_M 0xFEFEFE
;VIDEO_MODES
%define SHORT_TEXT_MODE 0x01
%define SHORT_TEXT_MODE_C 0x02
%define WIDE_TEXT_MODE 0x03
%define WIDE_TEXT_MODE_C 0x04
%define GRAPHICAL_MODE 0x05
%define GRAPHICAL_MODE_C 0x13
;%define GRAPHICAL_MODE_SHORT 0x05
%define GRAPHICAL_MODE_SHORT_C 0x13
;%define GRAPHICAL_MODE_SHORT_MC 0x13
;%define GRAPHICAL_MODE_MC 0x00
;%define GRAPHICAL_MODE_WIDE 0x00
%define GRAPHICAL_MODE_WIDE_C 0x12
%define GRAPHICAL_MODE_WIDE_MC 0x11
%macro bios_set_video_mode 1
mov ah, 0
mov al, %1
int 0x10
%endmacro
%macro bios_print_string 6
mov bp, %1 ; [ES:BP] is far pointer string to write
mov ah, 0x13 ; write string
mov al, 0x01 ; update cursoer after writing
mov bh, %3 ; page number
mov bl, %6 ; color attributes
mov cx, [%2] ; number of characters in string
mov dh, %4 ; row
mov dl, %5 ; column
int 0x10
%endmacro
drive.asm :
%define HARD_DISK_DRIVE_N 0x80
%define FLOPPY_DISK_DRIVE_N 0x0
%define COMPACT_DISK_DRIVE_N 0xE0
%macro bios_read_disk 6
mov bx, %1 ; buffer pointer, the offset
mov ah, 0x02
mov dl, %2 ; drive number, 80 for hard drives
mov ch, %3 ; cylinder number
mov cl, %4 ; sector number
mov dh, %5 ; head number
mov al, %6 ; sectors to read
int 0x13
jc .read_error
bios_print_string DRIVE_READ_SUCCESS_MSG, DRIVE_READ_SUCCESS_MSG_len, 0, 0, 0, BLACK_COLOR | WHITE_COLOR
.read_error:
bios_print_string DRIVE_READ_ERROR_MSG, DRIVE_READ_ERROR_MSG_len, 0, 0, 0, BLACK_COLOR | WHITE_COLOR
%endmacro
DRIVE_READ_ERROR_MSG: db 'Error reading from drive, carry flag set', NEW_LINE
DRIVE_READ_ERROR_MSG_len: dw 41
DRIVE_READ_SUCCESS_MSG: db 'Suc', NEW_LINE
DRIVE_READ_SUCCESS_MSG_len: dw 5