News:

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

My Boot Sector Problem

Started by akulamartin, March 19, 2012, 08:24:17 AM

Previous topic - Next topic

akulamartin

hey yall,i recently wrote a boot loader in NASM now writing it in MASM v11 (i use the quick editor,ml with /AT  and link16 with /TINY)  proves to be challenging here is my code any help will be highly appriciated :)

.model TINY
.386
.code
org 7c00h //not sure
mov  al,41h //character A
mov  bh,0
mov cx,7   //number of times to print
mov ah,0Ah
int 10h
org 510 //this works
dw 0AA55h
end

dedndave

you have to play tricks on the assembler to get the addresses to match
as a stand-alone file, it will be 512 bytes
in order for the linker to accept it as a tiny model program, the entry point has to be either 0 or 100h
but - when it is loaded into memory, it will be at 0000:7C00
one way to achieve this is to ORG 0, then use an offset to calculate the run-time addresses
if you use the forum search tool, you will find a few examples in the 16-bit sub-forum
by using the Advanced Search features, you can limit searches to that specific sub-forum, and search for "7C00"

also...
http://wiki.osdev.org/Expanded_Main_Page
they have a forum on the left pane

akulamartin

thanx  :U dedndave i should have caught that one before i also came across a boot sector written in masm which is much easier to dissect.. that's after I've removed the unwanted portions:

.386  ; There are a couple 386+ opcodes. 

_text SEGMENT PUBLIC USE16
  assume CS:_text, DS:_text
    org 0h


CRLF MACRO
  mov ax, 0E0Dh
  xor bx, bx
  int 10h
  mov al, 0Ah
  int 10h
ENDM


PRINT MACRO var

  pop dx
  mov di, var
  call printreg

  mov ax, 0E20h
  xor bx, bx
  int 10h

ENDM


EntryPoint:
  push sp
  push ss

  call NextLine  ; get original IP+5 on the STACK
NextLine:
  push cs

  push es
  push ds
  push bp
  push di
  push si
  push dx
  push cx
  push bx
  push ax

  ; print a pretty message
  mov ax, 1301h
  mov bx, 0007h
  mov cx, 23
  mov dh, 10
  mov dl, 1
  push cs
  pop es
  mov bp, String
  int 10h
  CRLF
  CRLF

  ; print the values of all the registers
  PRINT _AX
  PRINT _BX
  PRINT _CX
  PRINT _DX
  CRLF

  PRINT _SI
  PRINT _DI
  PRINT _BP
  CRLF

  PRINT _DS
  PRINT _ES
  CRLF

  PRINT _CS


  pop  ax
  sub ax, 5      ; ajust IP back five
  push ax

  PRINT _IP

  PRINT _SS
  PRINT _SP
  CRLF

  ; make a little beep
  mov ax, 0E07h
  int 10h


  ; nothing else to do, so hang
hang:
  jmp hang



; Big messy procedure that prints a three character string pointed to
; by DS:DI followed by the 16 bit hexidecimal number in DX.
printreg:

  mov ah, 0Eh
  xor bx, bx
  mov al, byte ptr [di]
  int 10h
  mov al, byte ptr [di+1]
  int 10h
  mov al, byte ptr [di+2]
  int 10h

  xchg dl, dh
  rol dl, 4
  rol dh, 4

  xor bx, bx
  mov ah, 0Eh
  mov cx, 4
ploop:
  mov al, dl
  and al, 0Fh
  shr dx, 4
  add al, '0'

  cmp al, '9'
  jbe nochange

  add al, 'A' - '9'-1

nochange:

  int 10h

  loop ploop

  RET



; Data Section.
;
; Notice that all the data pointers must have 7C00h added to it.  This is
; because the bootsector is loaded to 0000:7C00h, so the base offset is
; 7C00h.  However, the assembler thinks that the base offset is 0000h,
; so the 7C00h's are required to "fix-up" the base offest.
;
; Yes, there are many better ways of getting around this, but it's my code
; and I can do what I want!  What's that about my attitude?
;

String = $ + 7C00h
  db "initial register values"

_AX = $ + 7C00h
  db "AX="
_BX = $ + 7C00h
  db "BX="
_CX = $ + 7C00h
  db "CX="
_DX = $ + 7C00h
  db "DX="

_SI = $ + 7C00h
  db "SI="
_DI = $ + 7C00h
  db "DI="
_BP = $ + 7C00h
  db "BP="
_SP = $ + 7C00h
  db "SP="
_IP = $ + 7C00h
  db "IP="

_CS = $ + 7C00h
  db "CS="
_DS = $ + 7C00h
  db "DS="
_ES = $ + 7C00h
  db "ES="
_SS = $ + 7C00h
   db "SS="


ORG 510    ; Make the file 512 bytes long

  DW 0AA55h  ; Add the boot signature

_text ENDS

  END EntryPoint

dedndave

i would make an equate at the beginning of the program
BOOT_OFS EQU 7C00h

then, when you load an address
        mov     si,offset _AX+BOOT_OFS

or, if you load a word...
        mov     ax,SomeWord+BOOT_OFS

akulamartin

nah....thats a long way which other way can i use just a couple of lines for the org 7c00h thats like the only hurdle

P1

#5
Quote from: akulamartin on March 19, 2012, 08:24:17 AM
hey yall,i recently wrote a boot loader in NASM now writing it in MASM v11 (i use the quick editor,ml with /AT  and link16 with /TINY)  proves to be challenging here is my code any help will be highly appriciated :)
I hope you realize, that we have a number of new members, who's requests match that of less than reputable purposes.

You indicated that this is a re-write of code.  A post of the original code would be a good gesture on your part.

So please share with us, the original use/purpose of the NASM code for a boot loader ???

Then please share the need to cross code the project to MASM ???

So this is your opportunity, to share your need before the topic is locked for further discussion.

Regards,  P1   :8)

akulamartin

@Micheal this is the  boot sector(MASM) that gives me 32kb,i intent to have a skeleton for future projects:
.model TINY
.386
.code
org 7c00h //here is the issue 
mov  al,41h
mov  bh,0
mov cx,7   
mov ah,0Ah
int 10h
org 510 
dw 0AA55h
end

what i want is similar code for the org 7c00h or an entire new code  i've gone through the other sub forums but i still don't understand how to do the  0000:7c00 for the memory

The NASM version:

[BITS 16]   
[ORG 0x7C00]   

//my code here

JMP $       

TIMES 510 - ($ - $$) db 0   ;fill the rest of sector with 0
DW 0xAA55

sinsi

Since 7c00 can be 0000:7c00 or 07c0:0000, just make it 'org 0' (not really needed) and load segment 7c0 into ds/es.
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

they often make a segment "translation" by pushing a CS and label offset, then executing a RETF

akulamartin

@dendave,sinsi thanx guys but i prefer working examples kindly give me one using my code

dedndave

here is some code i wrote a while back...
http://www.masm32.com/board/index.php?topic=12028.msg91657#msg91657
it demonstrates the segment translation as i mentioned above and is well commented
i will leave incorporation into your code up to you   :P

P1

Quote from: akulamartin on March 23, 2012, 11:49:17 AM@Micheal this is the  boot sector(MASM) that gives me 32kb,i intent to have a skeleton for future projects:
Please give specific "projects" that required a boot loaded.

I can tell you exactly why I had written a bootloader for myself, that was way back in MASM 5.0 day, completely legal copy, with the documentation.
Quote from: P1 on March 23, 2012, 04:01:27 AMSo please share with us, the original use/purpose of the NASM code for a boot loader ???
Another dodge by you, and I will assume the worst purpose here.  Therefore lock the thread.
Quote from: Forum Rules3. Legality of content is not a negotiable matter in the forum. Assembler programming is mainstream programming and is primarily used by professional programmers who require the performance in specialised areas. Low level coding is both allowed and encouraged but there will be no viral or trojan technology allowed including technical data under the guise of AV technology, no cracking and similar activities in the guise of "Reverse Engineering", no hacking techniques or related technology and no support or help with or reference to pirated software. There will also be no links to pages that support or display any of these or any other illegal areas of coding.
We have a ZERO tolerance policy for virus writers.

Regards,  P1  :8)

Rockphorr

Quote from: P1 on March 23, 2012, 05:13:47 PM
Please give specific "projects" that required a boot loaded.

Regards,  P1  :8)

it is very easy.
task1 - create the tool which offload dos or other os  and transfer execution to boot other system
task2 - create program with native data exchange with some device
task3 - create program that uses particular modes of cpu

i think that creation of something is more intresting that virus writing
Strike while the iron is hot - Бей утюгом, пока он горячий

qWord

Is this a witch-hunt?  Why is it dubious to translate a boot loader from NASM to MASM?
Writing a simple boot loader, is a common beginners task.
FPU in a trice: SmplMath
It's that simple!

akulamartin

 ::) its for my kernel and i dont why im being grilled i just want a masm bootsector bcoz the nasm version was easier to work with ive seen this question 1000+ times so why is mine all of a sudden "virus/hacker" like??? is it the words im using?!