0

I'm trying to make my own OS (it's a project). For this project I created a simple bootloader which would wait for the user to input the height and width of an geometric figure (like a square) .

Then the bootloader would show the figure after the user presses enter. When I simply run it on windows (I ran the com version of the assembly) it works perfectly. But on a VM (oracle) it just shows the "_" character. This is the bootloader:

[BITS 16]
[ORG 0x7C00]

main:
    ;mov ah,02h
    ;mov bh,0h
    ;mov dh,0h    <---tried even this(it suppose to create a cursor)
    ;mov dl,0h


    mov ax,00000011b   ;color
    push ax
    mov ax,0    ;fill
    push ax


    ;HEIGHT
    call read_one_key
    mov ah,0h;clear ax
    push ax

    ;WIDTH
    call read_one_key
    mov ah,0h;clear ax
    push ax

    mov ax,100    ;X POS
    push ax
    mov ax,100    ;Y POS
    push ax

    call pause ;wait for enter
    call rectangle

jmp $


rectangle:
    ;STACK:
    ; ----14  ->line color
    ; ----12  -> fill
    ; ----10  -> height
    ; ---- 8  -> width
    ; ---- 6  -> x pos  --|
    ; ---- 4  -> y pos  --| of the top left corner

    ;Reads from stack
    push bp
    mov bp,sp

    ;Switch to VGA mode
    mov ah,00h
    mov al,13h
    int 10h

    ;mov bx,[bp+4] ;takes the last registered parameter
    mov cx,[bp+6] ;takes the x (column)-will change
    mov dx,[bp+4] ;the line is being drwn on a single row
    mov al,[bp+14]

    loop_hor_to_R:
        ;Row remains the same
        ;The column changes
        inc cx

        call point

        mov bx,[bp+8]
        add bx,[bp+6]       
        cmp bx,cx
        jne loop_hor_to_R

    loop_ver_to_D:
        ;Row changes
        ;The column remains the same (was set previusly in bx)
        inc dx

        call point

        mov bx,[bp+4]
        add bx,[bp+10]
        cmp bx,dx
        jne loop_ver_to_D


    loop_hor_to_L:
        ;Row remains the same
        ;The column changes
        dec cx

        call point   

        mov bx,[bp+6] ;left limit of square(starting x)
        cmp bx,cx
        jne loop_hor_to_L   


     loop_ver_to_U:
        ;Row changes
        ;The column remains the same (was set previusly in bx)
        dec dx

        call point

        mov bx,[bp+4]
        cmp bx,dx
        jne loop_ver_to_U 

    pop bp
    ret

point:
    ;CX ,DX-column and row
    mov ah,0Ch
    mov bh,0h  ;page number
    int 10h
    ret

read_one_key:
    ;reads a letter from keyboard and transforms it in a number
    ;the number is stored in al
    mov ah,01h
    int 21h
    ret

pause:
    ;waits for enter to be pressed
    ;Switch to text mode

    text_loop:
        ;Read key
        mov ah,01h
        int 21h
        cmp al,0Dh;Enter code in hex
        jne text_loop

    ret

write_text:
    mov ah,02h
    mov dl,'!'
    int 21h
    ret

; End Matter
times 510-($-$$) db 0   ; Fill the rest with zeros
dw 0xAA55       ; Boot loader signature

I haven't implemented the fill yet. This is what I get when running it on VM:


enter image description here

Why is that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sergiu reznicencu
  • 1,039
  • 1
  • 11
  • 31
  • 1
    `int 21h` is not available in a bare metal environment (like a bootloader at startup). That is a DOS interrupt which is only available after MS-DOS loads. You'll have to code something that uses BIOS routines or interfaces with the keyboard controller directly. – Michael Petch Jun 11 '16 at 16:34
  • You should also explicity set up the _DS_ register at the top of your bootloader. It isn't guaranteed to be what your program expects. In your case _DS_ should be set to 0 since you use a an ORG (origin point) of 0x7c00. I have some general bootloader tips in this other [Stackoverflow answer](http://stackoverflow.com/a/32705076/3857942) – Michael Petch Jun 11 '16 at 16:36
  • Is it only the 21 that can't be accesed in the boot stage? Or every int can't be accesed? – sergiu reznicencu Jun 11 '16 at 16:41
  • @Michael: Can you suggest me how to resolve the keyboard problem? I found the 16 interrupt with AH 0h. It reads the ascii code of the key (it's used for keystrokes).Do you know if this works? – sergiu reznicencu Jun 11 '16 at 16:48
  • Done it. Thak you guys. I've used the 16 interrupt to read the keyboard. – sergiu reznicencu Jun 11 '16 at 16:52
  • This Wiki article has a table of most of the [DOS interrupts](https://en.wikipedia.org/wiki/MS-DOS_API#Interrupt_vectors_used_by_DOS). None of them can be used in a bare metal environment. As for other interrupts most are BIOS related and are available in a bare-metal environment. [Ralf Brown's interrupt list](http://www.ctyme.com/rbrown.htm) is a bible for interrupts (DOS and BIOS). In particular he has broken down the BIOS interrupts in this [webpage entry](http://www.ctyme.com/intr/cat-003.htm) – Michael Petch Jun 11 '16 at 17:09

0 Answers0