News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Error in Bootloader masm

Started by JnZn558, December 10, 2011, 10:05:51 PM

Previous topic - Next topic

JnZn558

I have changed some code for masm, but it still contain error. pls help to fix it.


; Datei: test.asm
.386
.model TINY

.code
start:
    org 7C00h
                    ; Erst brauchen wir einen Stack.
    cli                ; Keine Interrupts!
    mov ax, 9000h      ; Stackadresse
    mov ss, ax      ; SS = 0x9000 (unser Stack)
    mov sp, 0       ; SP = 0x0000  (der Stackpointer)
    sti             ; Interrupts zulassen
   
    ; Segmentregister initialisieren (f黵 Zugriff auf bootdrv notwendig)
    mov ax, 0
    mov es, ax
    mov ds, ax
   
    ; Bootlaufwerk aus DL speichern
    mov [bootdrv], dl
 
    ;Lade unseren Kernel
    call load
   
    ;Springe zu diesem Kernel
    mov ax, 1000h ; Die Adresse des Programms
    mov es, ax     ; Segmentregister updaten
    mov ds, ax
    jmp ds:0
   
    bootdrv db 0 ;Das Bootlaufwerk
    loadmsg db "Laden...',13,10,0
   
    ; Einen String ausgeben:
    putstr:
    lodsb             ; Byte laden
    or al,al
    jz short putstrd  ; 0-Byte? -> Ende!
 
    mov ah,0Eh        ; Funktion 0x0E
    mov bx,0007h      ; Attribut-Byte (wird nicht ben鰐igt)
    int 10h           ; schreiben
    jmp putstr        ; N鋍hstes Byte
    putstrd:
    retn
   
    ; Lade den Kernel vom Bootlaufwerk
    load:
    ; Diskdrive reset (Interrupt 13h, 0)
    mov ax, 0          ; Die gew黱schte Funktion (reset)
    mov dl, [bootdrv]  ; Dieses Laufwerk ist gew黱scht
    int 13h            ; Den Interrupt ausf黨ren
    jc load            ; Geht nicht? -> Noch mal!
 
    load1:
    mov ax,1000h       ; ES:BX = 0x10000
    mov es,ax
    mov bx, 0
 
    ; Sektoren lesen (Interrupt 13h, 2)
    mov ah, 2         ; Funktion 2 (Lesen)
    mov al, 5         ; Lese 5 Sektoren
    mov cx, 2         ; Cylinder=0, Sector=2
    mov dh, 0         ; Head=0
    mov dl, [bootdrv] ; Laufwerk aus Vorgabe
    int 13h           ; ES:BX =  Daten vom Laufwerk
    jc load1          ; Fehler? Noch mal!
    mov si, offset loadmsg
    call putstr       ; Meldung ausgeben
    retn
 
    times db (510-$) dup(0)   ; Dateil鋘ge: 512 Bytes
    dw 0AA55h                 ; Bootsignatur

; **********************************
; ***********End Boot Loader********
; **********************************
END start



Assembling: main.asm
main.asm(73) : error A2094: operand must be relocatable
main.asm(30) : error A2023: instruction operand must have size
main.asm(69) : error A2022: instruction operands must be the same size


line 30 > jmp ds:0
line 69 > mov si, offset loadmsg
line 73 > times db (510-$) dup(0)

MichaelW

#1
With the code as posted, assembling with ML 6.14, I get:

test0.asm(33) : error A2046: missing single or double quotation mark in string
test0.asm(73) : error A2094: operand must be relocatable
test0.asm(30) : error A2023: instruction operand must have size
test0.asm(69) : error A2006: undefined symbol : loadmsg


After I change the single quote (') on line 33 to a double quote ("), I get:

test.asm(73) : error A2094: operand must be relocatable
test.asm(30) : error A2023: instruction operand must have size
test.asm(69) : error A2022: instruction operands must be the same size


After I change line 73 to:

org 7C00h + 510


I get:

test.asm(30) : error A2023: instruction operand must have size
test.asm(69) : error A2022: instruction operands must be the same size


After I move the .386 directive to the next line after the .model directive, to set the segment word size to 16 bits instead of 32 bits, so offset addresses will be 16-bit values instead of 32-bit values, I get:

test.asm(30) : error A2023: instruction operand must have size


For the above see Using Full Segment Definitions, Setting Segment Word Sizes (80386/486 Only) here:

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_02.htm

For line 30 I'm guessing that you want to jump to the loaded code, and that the jump should be a far jump that specifies both a segment address (1000h) and an offset address (0). For that I think something like this should work:

; line 30:
jmp DWORD PTR dest
; line 34:
dest dw 0, 1000h

eschew obfuscation

JnZn558

#2
thx very much, i compile it as following, but It results that boot.bin been created have file size of 32 kb, it is too big, how can I set it to 512 byte?

ml /c /AT main.asm
link16 /tiny main.obj, boot.bin;

qWord

Quote from: JnZn558 on December 10, 2011, 10:05:51 PM   org 7C00h
This directive creates 7C00h zero bytes - remove it.
FPU in a trice: SmplMath
It's that simple!

mineiro

.code
org 7C00h
start:


You can do that jmp this way:

;Springe zu diesem Kernel
    mov ax, 1000h ; Die Adresse des Programms
    mov es, ax     ; Segmentregister updaten
    mov ds, ax
push ds ;segment
push 0  ;offset
retf      ;jmp
;    jmp ds:0

JnZn558

Quote from: mineiro on December 12, 2011, 01:19:21 AM
.code
org 7C00h
start:


You can do that jmp this way:

;Springe zu diesem Kernel
    mov ax, 1000h ; Die Adresse des Programms
    mov es, ax     ; Segmentregister updaten
    mov ds, ax
push ds ;segment
push 0  ;offset
retf      ;jmp
;    jmp ds:0


thx, it works. but can you tell me why the following not work?,


jmp DWORD PTR dest
dest dw 0000h, 1000h


with bochs debugger I get someting like this


jmp far ptr 0x7c24      ; why is it not 1000:0000

Rockphorr

Quote
Code:
jmp far ptr 0x7c24      ; why is it not 1000:0000

cause it is indirect call - this call uses var with address of target

jmp to 1000:0000 -
   mov ax, 1000h ; Die Adresse des Programms
    mov es, ax     ; Segmentregister updaten
    mov ds, ax

push ds
xor ax,ax
push ax
retf


Strike while the iron is hot - Бей утюгом, пока он горячий