MASM32 error while assembling / begin: / end begin

Started by Earnie, July 15, 2010, 06:42:38 PM

Previous topic - Next topic

dedndave

oh - another way is to use PROC to generate the code label
_main   PROC

;main program

_main   ENDP

        END     _main


also - DOS device drivers are a special case
the entry is always 0, even though there is no executable code at 0 (similar to ROMable code)
you might try...
        END     0
or just
        END

EXE2BIN will only accept entry point values of 0 or 100h

Earnie

Thanks so far, but I can't test the code. I use Virtual PC to emulate DOS 6.22 and for that I need an .iso file. I wanted to include my driver.sys in the DOS6.22.iso but it didn't work. Problem is someone else though:

I loaded the DOS6.22.iso into WinImage and extracted it.
I didn't change anything.
Just loaded the whole folder into InfraRecorder (free burn software) and created another DOS6.22.iso
I then loaded the DOS6.22.iso into Virtual PC and restarted.
DOS did not load (which it did with the original DOS6.22.iso).

Do I have to use a special program to create the .iso ? Is there an easier way to develop and test a DOS driver?

I take it I have to emulate it or else I could damage something.
     

EDIT: I just noticed that the new file is only half the size of the original. Of course it didn't work.

dedndave

creating a floppy is probably the easiest way - provided you have a floppy drive
if the iso has to be bootable (like a CD image), you might try googling "El Torito"

Earnie

i have managed to manipulate an .iso file... so far so good...

I loaded it into Virtual PC and DOS started like it always did !

My config.sys only reads "DEVICE=DRIVER.SYS" now.

And nothing happens.

dedndave

hard to say exactly what the problem is
but, post the code, and i'll have a look at it

oh - i take it you are creating a flat binary file, somehow
i used EXE2BIN.exe

Earnie

OK, seems that the whole assembling process didn't work, although I thought it did

SimpleDriver.asm

;************************************************************
;*   This is a simple Device Driver                         *
;************************************************************


;************************************************************
;*   INSTRUCTING THE ASSEMBLER                              *
;************************************************************

cseg      segment   para       public  'code'     
simple    proc      far                 
          assume    cs:cseg,es:cseg,ds:cseg

;************************************************************
;*   MAIN PROCEDURE CODE                                    *
;************************************************************

begin = $

;************************************************************
;*   DEVICE HEADER REQUIRED BY DOS                          *
;************************************************************

next_dev      dd     -1             
attribute     dw     2000h           
strategy      dw     dev_strategy
interrupt     dw     dev_int
dev_name      db     'SIMPLE$ '

;************************************************************
;*   WORK SPACE FOR OUR DEVICE DRIVER                       *
;************************************************************

rh_off        dw    ?
rh_seg        dw    ?
msgl          db    07h
              db    'The Waite Group Simple Device Driver! '
              db    0dh,0ah,07h,'$'
   
;************************************************************
;*   THE STRATEGY PROCEDURE                                 *
;************************************************************

dev_strategy:
        mov    cs:rh_seg,es
        mov    cs:rh_off,bx
        ret 

;************************************************************
;*   THE INTERRUPT PROCEDURE                                *
;************************************************************

dev_int:
        cld   
        push  ds
        push  es
        push  ax
        push  bx
        push  cx
        push  dx
        push  di
        push  si

        mov   al,es:[bx]+2
        cmp   al,0
        jnz   exit3
        rol   al,1
        lea   di,cmdtab
        mov   ah,0
        add   di,ax
        jmp   word ptr[di]

cmdtab  label   byte
        dw      init 

;************************************************************
;*   YOUR LOCAL PROCEDURES                                  *
;************************************************************

initial  proc   near
         lea    dx,msgl
         mov    ah,9
         int    21h
         ret
initial  endp
       

;************************************************************
;*   DOS COMMAND PROCESSING                                 *
;************************************************************

init:   call   initial
        jmp    exit2

;************************************************************
;*   ERROR EXIT                                             *
;************************************************************

exit3:  mov    es:word ptr 3[bx],8103h
        jmp    exit1

;************************************************************
;*   COMMON EXIT                                            *
;************************************************************

exit2:
        mov    es:word ptr 3[bx],0100h
exit1:  mov    bx,cs:rh_off
        mov    es,cs:rh_seg
exit0:  pop    si
        pop    di
        pop    dx
        pop    cx
        pop    bx
        pop    ax
        pop    es
        pop    ds
        ret

;************************************************************
;*   END OF PROGRAM                                         *
;************************************************************

simple  endp
cseg    ends
        end  OFFSET begin 

; program end


I typed this in masm32\bin

ml SimpleDriver.asm SimpleDriver.obj

And I got this:

QuoteObject Modules [.obj]: SimpleDriver.obj+
Object modules [.obj]: "SimpleDriver.obj"
Run File [SimpleDriver.exe]: "SimpleDriver.exe"
List File [nul.map]: NUL
Libraries [.lib]:
Definitions File [nul.def]:
SimpleDriver.obj(SimpleDriver.asm) : error L2025 : initial : symbol defined more than once
SimpleDriver.obj(SimpleDriver.asm) : error L2025 : simple : symbol defined more than once
LINK: warning L4021 : no stack segment

There were 2 errors detected

Antariy

Quote from: Earnie on July 20, 2010, 06:29:14 PM
Thanks so far, but I can't test the code. I use Virtual PC to emulate DOS 6.22 and for that I need an .iso file. I wanted to include my driver.sys in the DOS6.22.iso but it didn't work. Problem is someone else though:

I loaded the DOS6.22.iso into WinImage and extracted it.
I didn't change anything.
Just loaded the whole folder into InfraRecorder (free burn software) and created another DOS6.22.iso
I then loaded the DOS6.22.iso into Virtual PC and restarted.
DOS did not load (which it did with the original DOS6.22.iso).

Do I have to use a special program to create the .iso ? Is there an easier way to develop and test a DOS driver?

I take it I have to emulate it or else I could damage something.
     

EDIT: I just noticed that the new file is only half the size of the original. Of course it didn't work.



Earnie
to boot from image (or ISO) you need not only files from disk (image of floppy) but and boot-sector for ISO-image. Open floppy image in WinImage, and select menu "Image->Boot Sector Properties" Click Save. Select the name and place for boot sector and save it.
In ISO-burning software burn the files as bootable image, as bootsector select saved in WinImage sector. Make the emulation of floppy ON.
I don't know InfraRecorder, I use Nero. So - find all options manually, I cannot advice something in InfraRecorder :(

P.S. Maybe, today I cannot answer to you questions, if it be happen. Don't umbrage.

dedndave

well - i see a few issues with the code
mostly matters of preference   :P
i haven't fully examined it to see if it correctly communicates with the DOS request header structure
also - i have long lost my documentation on the request header, although - some of it i remember - i can probably find it online

one thing i think you may be having trouble with is the file format, itself
the linker is going to generate an EXE file
in order to load that as a DOS device driver, i think the correct extension is .HEX - i forget
i have never used this format for DOS drivers, as there is no advantage to it - only disadvantages
it is much simpler to generate a flat binary named as .SYS
this is very similar to generating a tiny model (.COM) program, except the entry point for a driver is 0 (100h for .COM)
as with .COM programs, .SYS device drivers must have no relocatable elements and must fit into a single 64 Kb segment
as i recall, EXE2BIN came with most versions of DOS
in any event, it is a little program that essentially strips off the EXE header from a file and renders the executable part as a "raw" binary

EXE2BIN MyDriver.exe MyDriver.sys

this will create the .SYS file from the .EXE file

with older versions of EXE2BIN, i think the output extension had to be .BIN - i don't recall   :P

clive

Quote from: Earnie
I typed this in masm32\bin

ml SimpleDriver.asm SimpleDriver.obj

Because masm will pass the SimpleDriver.Obj down to the linker, and thus the linker will get SimpleDriver.obj TWICE. The syntax would presumably be ML SIMPLEDRIVER.ASM

Personally, I'd be using 8.3 naming for DOS drivers (ie simple.xxx), and it will assemble/link like this

\masm32\bin\ml -c simple.asm
\masm32\bin\link16 /TINY simple.obj,simple.sys;


Although I'm pretty sure DOS 6.22 will load EXE type driver files.
It could be a random act of randomness. Those happen a lot as well.

Earnie

clive, I followed your advice. No errors so far, but the driver doens't do anything (apparently).

config.sys


DEVICE=HIMEN.SYS /testmen:off
FILES=30
BUFFERS=20

[b]DEVICE=simple.SYS[/b]
DEVICE=cd1.SYS /D:banana

rem DEVICE=cd1.SYS /D:banana /:1f0,14
rem DEVICE=cd1.SYS /D:banana /:170,15
rem DEVICE=cd1.SYS /D:banana /:170,10
rem DEVICE=cd1.SYS /D:banana /:1e8,12
rem DEVICE=cd1.SYS /D:banana /:1e8,11
rem DEVICE=cd1.SYS /D:banana /:168,10
rem DEVICE=cd1.SYS /D:banana /:168,9

LASTDRIVE=Z


That's my config.sys. I can't see anything happening (additiionally to what is supposed to happen) when I load the .iso into Virtual PC.
The driver is supposed to make a single beep.

dedndave

yah - i think they put the EXEC loader in before config.sys around DOS 3   :P
still - never played with it - don't want to advise how to do it - lol

here is a do-nothing DOS device driver that should work
notice, it must be EXE2BIN'ed into a flat raw binary file

_TEXT   SEGMENT WORD PUBLIC 'CODE'
        ASSUME  CS:_TEXT

        ORG     0

HEADER:
        DD      -1
        DW      2000h
        DW      STRAT
        DW      INTRP
        DB      'NULL$$$$'

RHAPTR  LABEL   DWORD
RHAOFS  DW      ?
RHASEG  DW      ?

STRTEST DB      'Test Device Driver Loaded',7,0Dh,0Ah,24h

;--------------------------------------

STRAT   PROC    FAR

        MOV     CS:RHAOFS,BX
        MOV     CS:RHASEG,ES
        RET

STRAT   ENDP

;--------------------------------------

INTRP   PROC    FAR

        PUSHF
        PUSH    DS
        PUSH    ES
        PUSH    AX
        PUSH    BX
        PUSH    CX
        PUSH    DX
        PUSH    BP
        PUSH    SI
        PUSH    DI

        PUSH    CS
        POP     DS

        ASSUME  DS:_TEXT

        MOV     DX,OFFSET STRTEST
        MOV     AH,9
        INT     21h

        CLD
        LES     DI,RHAPTR
        ADD     DI,3
        MOV     AX,100h
        STOSW
        ADD     DI,8
        STOSB
        MOV     AH,AL
        STOSW
        MOV     AX,CS
        STOSW

        POP     DI
        POP     SI
        POP     BP
        POP     DX
        POP     CX
        POP     BX
        POP     AX
        POP     ES
        POP     DS
        POPF
        RET

INTRP   ENDP

;--------------------------------------

_TEXT   ENDS

        END     HEADER

Earnie

If it doesn't do anything, how do I know it's working?
What puzzles me is that there is no error, even if I write "simple2.sys" (the file doens't exist) in the config.sys.
It's like the line "DEVICE=simple.sys" is ignored. If that line were to be executed, there would have to be that beeping sound.

dedndave

well - the driver i posted will display "Test Device Driver Loaded"

but, that's about all it does
it sets the request header status word to 100h (status = done)
it sets the number of devices installed to 0 (i think that's the number of block devices - can't remember)
it sets the release address to CS:0

you can add a 7 in there if you want audible feedback - may not be a bad idea

oh - i forgot to put an assume directive in there - let me update the previous post
i also added the BEL character for audible confirmation

the device ought to work
the main purpose is to test your setup
if my "null$$$$" device works, and yours does not - that tells you your code is amiss
if neither device works, it tells you there is something else wrong

dedndave

in case you're having troubles, i assembled the driver
i also converted it with EXE2BIN
see attached...

dedndave

ok - i cobbled together an HTML of command codes, request header format, status bits, and error codes
see attachment

also, i found this d/l of several DOS device driver examples with source   :bg

http://www.programmersheaven.com/download/1399/Download.aspx