0

My Assembly code is longer than 512 lines but if times' value is bigger than 512, VirtualBox gives me VERR_VD_RAW_SIZE_MODULO_512 error (and it fails to load the image file). How can I solve this?

Code:

BITS 16

disk_buffer equ 24576

mov sp, 4096d
mov ax, 7c0h
mov ds, ax



;mov ah, 09h
;mov cx, 1000h
;mov al, 20h

;mov bl, 17h

;mov bl, 07h
;int 10h



;mov ax, dialog_string_1        ; Ask if user wants app selector or command-line
;mov bx, dialog_string_2
;mov cx, dialog_string_3
;mov dx, 1          ; We want a two-option dialog box (OK or Cancel)
;call os_dialog_box

mov si, bootmsg
call printstring


;ah
;01 - waits key press, displays key
;08 - waits key press, hides key
;09 - displays strings

print_input:
    call nl
    mov si, inputmsg
    call printstring
    input:
        mov ah, 00h
        int 16h
        cmp al, 13 ;ENTER
        je proc_cmd
        cmp al, 8 ;BACKSPACE
        je proc_backspace
        cmp al, 97 ;a
        jl input
        cmp al, 122 ;z
        ja input
        ;mov ah, 00
        ;mov si, ax
        mov si, inputkey
        call printstring

        jmp input

proc_cmd:
    call nl
    mov si, errormsg
    call printstring
    jmp print_input

proc_backspace:
    call bs
    jmp input






os_draw_block:
    pusha

.more:
    call os_move_cursor     ; Move to block starting position

    mov ah, 09h         ; Draw colour section
    mov bh, 0
    mov cx, si
    mov al, ' '
    int 10h

    inc dh              ; Get ready for next line

    mov ax, 0
    mov al, dh          ; Get current Y position into DL
    cmp ax, di          ; Reached finishing point (DI)?
    jne .more           ; If not, keep drawing

    popa
    ret

os_wait_for_key:
    mov ah, 0x11
    int 0x16

    jnz .key_pressed

    hlt
    jmp os_wait_for_key

.key_pressed:
    mov ah, 0x10
    int 0x16
    ret

os_show_cursor:
    pusha

    mov ch, 6
    mov cl, 7
    mov ah, 1
    mov al, 3
    int 10h

    popa
    ret

os_hide_cursor:
    pusha

    mov ch, 32
    mov ah, 1
    mov al, 3           ; Must be video mode for buggy BIOSes!
    int 10h

    popa
    ret

os_move_cursor:
    pusha
    mov bh, 0
    mov ah, 2
    int 10h
    popa
    ret

os_draw_background:
    pusha

    push ax             ; Store params to pop out later
    push bx
    push cx

    mov dl, 0
    mov dh, 0
    call os_move_cursor

    mov ah, 09h         ; Draw white bar at top
    mov bh, 0
    mov cx, 80
    mov bl, 01110000b
    mov al, ' '
    int 10h

    mov dh, 1
    mov dl, 0
    call os_move_cursor

    mov ah, 09h         ; Draw colour section
    mov cx, 1840
    pop bx              ; Get colour param (originally in CX)
    mov bh, 0
    mov al, ' '
    int 10h

    mov dh, 24
    mov dl, 0
    call os_move_cursor

    mov ah, 09h         ; Draw white bar at bottom
    mov bh, 0
    mov cx, 80
    mov bl, 01110000b
    mov al, ' '
    int 10h

    mov dh, 24
    mov dl, 1
    call os_move_cursor
    pop bx              ; Get bottom string param
    mov si, bx
    call printstring

    mov dh, 0
    mov dl, 1
    call os_move_cursor
    pop ax              ; Get top string param
    mov si, ax
    call printstring

    mov dh, 1           ; Ready for app text
    mov dl, 0
    call os_move_cursor

    popa
    ret

bs:
    mov al, 8 ;BACKSPACE
    mov ah, 0eh
    int 10h
    mov al, 32 ;SPACE
    mov ah, 0eh
    int 10h
    mov al, 8 ;BACKSPACE
    mov ah, 0eh
    int 10h
    ret

nl:
    mov al, 0ah ;10
    mov ah, 0eh
    int 10h
    mov al, 0dh ;13
    mov ah, 0eh
    int 10h
    ret

printstring:
    lodsb
    cmp al, 0h
    je printstring_eof
    mov ah, 0eh
    int 10h
    jmp printstring
    printstring_eof:
    ret


os_init_msg db 'AdvOS a hos geldiniz', 0
os_version_msg db 'Versiyon 0.1', 0

dialog_string_1 db 'Thanks for trying out MikeOS!', 0
dialog_string_2 db 'Please select an interface: OK for the', 0
dialog_string_3 db 'program menu, Cancel for command line.', 0

bootmsg db 'AdvOS', 10, 13, 'v0.1', 0
inputmsg db '> ', 0
inputkey db 'f', 0
errormsg db 'Hata', 0
cursorp db ''
inputstring db ''

dw 0xaa55
times 450 - ($ - $$) db 0
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Nafe Bon
  • 33
  • 7
  • 2
    The line count does not mean anything. The bootloader size (in bytes) matters. – CoderCharmander Jan 08 '20 at 14:00
  • If I take the `times` to upper from my any line of code, it fails again. Example I changed 512 to 480 and put upper than my 32 line code, it failed. – Nafe Bon Jan 08 '20 at 14:02
  • can you show your code? – Paweł Łukasik Jan 08 '20 at 14:21
  • 2
    I am not an expert on boot loaders, I wrote a "Hello world" in vga text mode once... fairly recently... I think your bootloader can be any size as long as you can make the first 512 do enough to mount up and load the rest into memory and jump to it... the second part can be arbitrarily large. – Grady Player Jan 08 '20 at 14:37
  • So how can I write bigger than 512 bytes? – Nafe Bon Jan 08 '20 at 14:57
  • you can read from a disk with `int 13h` and load that into an arbitrary address, not something I have actually tried https://wiki.osdev.org/Rolling_Your_Own_Bootloader#What_if_I_get_beyond_the_512_bytes_of_the_boot_sector.3F – Grady Player Jan 08 '20 at 16:01
  • My code does not work anymore. I compile it with `NASM` and rename it to `.img`. I deleted unused codes and the code is shorter than 512 bytes now. I compile, but VirtualBox can not open it. – Nafe Bon Jan 08 '20 at 16:18
  • 3
    `dw 0xaa55` has to go *after* `times 510 - ($ - $$) db 0`, to place the MBR signature as the last 2 bytes of a 512-byte boot sector. Your code has the wrong order and the wrong amount of padding. See [What does this asm expression \`64-$+buffer\` means?](//stackoverflow.com/a/59511280) and especially [How to fix "os.asm:113: error: TIMES value -138 is negative" in assembly language](//stackoverflow.com/q/53858770) which has a complete working example of a bootloader that loads more sectors, allowing a larger total code size. – Peter Cordes Jan 08 '20 at 16:28
  • Ok sorry, I think I changed its location when I was trying to put code after `times` line. – Nafe Bon Jan 09 '20 at 15:04

0 Answers0