Author Topic: please convert this masm code to nasm  (Read 12289 times)

nobody

  • Guest
please convert this masm code to nasm
« on: July 25, 2007, 02:53:20 PM »
Hello to all developers
I'm a newbie to NASM.
please convert this masm code to nasm
please help me~

-----------------------------------------------------------------

NAME    bsp

PUBLIC  _contextInit
    PUBLIC  _contextSwitch
    PUBLIC  _idle


bsp SEGMENT WORD PUBLIC 'CODE'

ASSUME  cs:bsp
    ASSUME  ds:nothing
    ASSUME  es:nothing
    ASSUME  ss:nothing


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Function:     contextInit()
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EVEN
_contextInit   PROC    FAR

push    bp
    mov     bp, sp

les     di, dword ptr ss:[bp+6]     ; Get pContext from the caller.

;
    ; Initialize the return address.
    ;
    push    ds
    lds     bx, dword ptr ss:[bp+10]    ; Get pFunc from the caller.
    mov     dx, ds
    mov     es:[di], bx
    mov     es:[di+2], dx

;
    ; Initialize the processor flags.
    ;
    pushf
    pop     ax
    or      ax, 0000001000000000b       ; Enable interrupts by default.
    mov     es:[di+4], ax          

;
    ; Initialize the stack segment.
    ;
    les     di, dword ptr ss:[bp+18]    ; Point to the task's stack.
    lds     bx, dword ptr ss:[bp+14]    ; Get pTask from the caller.
    mov     dx, ds
    mov     es:[di-4], bx               ; Place pTask onto the stack.
    mov     es:[di-2], dx

les     di, dword ptr ss:[bp+6]     ; Point to the task's context.
    lds     bx, dword ptr ss:[bp+18]    ; Get pStack from the caller.
    mov     dx, ds
    sub     bx, 8                       ; Save stack space for pTask.
    mov     es:[di+6], bx
    mov     es:[di+8], dx

;
    ; Initialize the data segment.
    ;
    pop     ds
    mov     dx, ds
    mov     es:[di+10], si
    mov     es:[di+12], dx

pop     bp
    ret

_contextInit   ENDP


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Function:    contextSwitch()
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EVEN
_contextSwitch   PROC    FAR

push    bp
    mov     bp, sp

;
    ; Get pOldContext from the stack.
    ;
    les     di, dword ptr ss:[bp+6]
    mov     dx, es
    mov     ax, di

;
    ; if (pOldContext == NULL) goto fromIdle;
    ;
    or      ax, dx
    jz      fromIdle

;
    ; Save the address of the end of this routine.
    ;
    mov     dx, cs
    lea     ax, switchComplete
    mov     es:[di], ax
    mov     es:[di+2], dx

;
    ; Save the processor flags.
    ;
    pushf
    pop     es:[di+4]

;
    ; Save the stack segment.
    ;
    mov     dx, ss
    mov     es:[di+6], sp
    mov     es:[di+8], dx

;
    ; Save the data segment.
    ;
    mov     dx, ds
    mov     es:[di+10], si
    mov     es:[di+12], dx

fromIdle:
    ;
    ; Get pNewContext from the stack.
    ;
    les     di, dword ptr ss:[bp+10]
    mov     dx, es
    mov     ax, di

;
    ; Restore the data segment.
    ;
    lds     si, dword ptr [di+10]

;
    ; Restore the stack segment.
    ;
    mov     dx, es:[di+8]
    mov     ax, es:[di+6]
    pushf                           ; Save the current interrupt state.
    pop     cx
    cli                             ; Disable interrupts.
    mov     ss, dx
    mov     sp, ax
    push    cx
    popf                            ; Restore the saved interrupt state.

;
    ; Restore the processor flags.
    ;
    push    es:[di+4]

;
    ; Restore the return address.
    ;
    push    es:[di+2]
    push    es:[di]

;
    ; Now return, taking the saved flags with us.
    ;
    iret

switchComplete:
    pop     bp
    ret

_contextSwitch   ENDP


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Function:    idle()
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EVEN
_idle            PROC FAR

idleLoop:
    jmp     idleLoop

_idle            ENDP


bsp ENDS

END

------------------------------------------------------------------------------

nobody

  • Guest
Re: please convert this masm code to nasm
« Reply #1 on: July 25, 2007, 06:49:21 PM »
>     NAME    bsp

Comment out.

>     PUBLIC  _contextInit
>     PUBLIC  _contextSwitch
>     PUBLIC  _idle

PUBLIC -> global

> bsp SEGMENT WORD PUBLIC 'CODE'

section bsp public class=CODE

>     ASSUME  cs:bsp
>     ASSUME  ds:nothing
>     ASSUME  es:nothing
>     ASSUME  ss:nothing

Comment out.

> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;
> ; Function:     contextInit()
> ;
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> EVEN

align 2 ; (not necessary)

> _contextInit   PROC    FAR

_contextInit:

>     push    bp
>     mov     bp, sp
>
>     les     di, dword ptr ss:[bp+6]     ; Get pContext from the caller.

les di, [bp + 6]  ; bp defaults to ss

>     ;
>     ; Initialize the return address.
>     ;
>     push    ds
>     lds     bx, dword ptr ss:[bp+10]    ; Get pFunc from the caller.

lds bx, [bp + 10]

>     mov     dx, ds
>     mov     es:[di], bx            

mov [es:di], bx
etc.

> _idle            ENDP
>
>
> bsp ENDS
>
> END

Comment out all the "end" junk - Nasm knows you're done when it falls off the end of the file. :)

Best,
Frank

nobody

  • Guest
Re: please convert this masm code to nasm
« Reply #2 on: July 26, 2007, 01:21:27 AM »
Thanks Frank,