Page 1 of 1
Simple problem with int 0x13 in bootloader
Posted: Fri Mar 16, 2007 9:00 pm
by billion_boi
hey all, im relatively new to assembly programing but i seem to be grasping the concepts easily. I got a bootloader running, its very simple, but it doesnt run int 0x13 and theirfor get the secondstage bootstrap running. Does anyone know where the problem might be in my source?
Posted: Fri Mar 16, 2007 11:41 pm
by B.E
First you don't set up a stack, second read the code sequentially (i.e read the code the same way th machine reads it) and you'll see the error. I'll give you a hint, it has something to do with PrintMsg
.
Posted: Sat Mar 17, 2007 10:28 am
by billion_boi
well i went over my bootstraps printmsg funciton a few more times and i kno the correct values (offsett and segment) of my string are in the registers. And since im new to all this maybe a bigger hint
Posted: Sat Mar 17, 2007 11:22 am
by urxae
billion_boi wrote:well i went over my bootstraps printmsg funciton a few more times and i kno the correct values (offsett and segment) of my string are in the registers. And since im new to all this maybe a bigger hint
Think about what happens after the first call...
Posted: Sat Mar 17, 2007 11:35 am
by ~
urxae wrote:billion_boi wrote:well i went over my bootstraps printmsg funciton a few more times and i kno the correct values (offsett and segment) of my string are in the registers. And since im new to all this maybe a bigger hint
Think about what happens after the first call...
Also, if that's a boot sector for a floppy, you should consider it having a valid FAT12 header when you can support it, because it will be both tedious to reload the disk contents by hand for every different test, and also it cannot be read easily on any computer just like a normal floppy.
Take a look at this:
http://scottie.20m.com/fat.htm
You should use lodsb in the print msg function
Posted: Sat Mar 17, 2007 12:49 pm
by anon19287473
You should use lodsb in the print msg function, to load the values, i think its faster.
Posted: Sat Mar 17, 2007 1:05 pm
by ~
Try to do something like this. It should make for a valid FAT12 boot sector, and it should also stop giving trouble with the print routine.
Code: Select all
[BITS 16] ;WE TELL TSM THAT THE CODE SHOULD BE COMPILED as 16BIT code
[ORG 0X7C00] ; WE TELL NASM WE WANT PROGY LOADED AT OFFSETT 0X700 INTO MEMORY
; so its loaded at 0x7C00 bytes from the segment 0000
_jmp: db 0EBh ;jmps 003E
_03E: db 03Ch
_nop: nop
_OEMID db " "
_bytesPerSector dw 0200h
_sectsPerCluster db 001h
_resrvedSectors dw 0001h
_numOfFATs db 002h
_numRootDirEntries dw 00E0h
_numSectors dw 0B40h
_mediaType db 0F0h
_numFATsectors dw 0009h
_sectorsPerTrack dw 0012h
_numHeads dw 0002h
_numHiddenSects dd 00000000h
_numSectorsHuge dd 00000000h
_driveNumber db 00h
_reserved db 00h
_signature db 29h
_volumeID db "0000"
_volumeLabel db " "
_FSType db "FAT12 "
main:
mov ax, 0x0000
mov ds, ax
mov si, String1
call PrintMsg
mov si, String2 ;THis stores Strings offsett into si (index register)
call PrintMsg
LoadBootstrap: ;befor bios interupt 0x13 can be run follwing registers must be set
mov ah, 0x02 ;Read disk sectors
mov al, 0x01 ;# of sectors to read (1)
mov ch, 0x00 ;Track 0
mov cl, 0x02 ;sector 2
mov dh, 0x00 ;head 0
mov dl, 0x00 ;drive 0 (floppy 1) floppy drive ex 0x00 0x01 etc hardrive 0x80 or 0x81...
;most bioses can only load first driver of floppy
mov bx, 0x1000 ;segment 0x1000
;the memory lcoation (seg:off) to copy to is es:bx
mov es, bx ;loading segment into segment register
mov bx, 0x0000 ;loading the offsett (start of segment)
.readsector
int 0x13 ;making the bios call
;when function returns it will make carryflag 0 if sucess or 1 if failure
jc .readsector ;If there was an error (carryflag=1) try again
mov ax, 0x1000
mov ds, ax ;getting bootstraps segment into segment refister
;because well be refencing that segment from now on in the bootstrap
jmp 0x1000:0x0000 ;Jump to bootstraps memory location!
PrintMsg:
mov ah, 0x0e ;ah= video function mode. of 256 modes we want teletype mode which is 0x0E. The mode requires values in al (character value), bh (bh=page number or type of screen, wel use visible page 0), and bl registers
mov bh, 0x00
mov bl,0x07 ; Text attribute (Controls the background and foreground colour (07 = White text, black background)
.NextChar:
mov al, [ds:Si]
inc si ;Increments the offsett of si to refence the next byte/character in the string
;The aboe two lines can be replaced with lodsb which Loads [si] into al and increment si
or al, al ;If al=0(meaning weve gotten to the last character of the string then the Zero flag is set
jz .Break ;Jum on zero (jumps wen the flag is 0)
int 0x10
jmp .NextChar
;Make sure bh and bl are out of the loop cuz they don have to be reloaded.
.Break:
ret ;Return to wherever function was called from
;JMP $ ; jumping to the same line of code in never ending loop
String1: db "Boot loader V0.01A", 13, 10, 0 ; DECLARING a varialbe with A DOUBLE BYTE
String2: db "Just befor loading bootstrap",13,10, 0 ; DECLARING a varialbe with A DOUBLE BYTE
times 510-($-$$) db 0 ;From current location to offset 510 tasm/nasm repeats instruction db (declare byte)
dw 0xAA55 ;0x55 and 0xAA are the two last bytes
; BECAUSE THATS A BOOTSIGNITURE THAT DEFINES A PROPER
;BOOT SECTOR
;OUR PROGGY IS NOW EXACTLY 512KB LONG
;New BIOSes seem to ignore the 0xAA55, but you should leave it in
;so your code works OK on old PCs. Also, the Master Boot Record
;(MBR) will not load the bootsector if this value is missing.
Now you could load your 512-byte second stage loader if it were the only file in a new floppy disk. In that case, instead of reading
Cylinder 0,
Head 0,
Sector 2, you'll have to read
Cylinder 0,
Head 1,
Sector 16 since that's the first cluster sector for FAT12 data area. Otherwise you will trash the FAT table if you write to "sector 2".
Posted: Sun Mar 18, 2007 10:02 am
by Combuster
back to topic, consider:
(1) starup
(2) call print message
(3) code for print message
(4) ret
what happens:
startup
print message
ret
print message (!)
Posted: Mon Mar 19, 2007 5:40 am
by billion_boi
AHHH! I Got it! I didnt call on the function to load the bootstrap! combuster, that visual helped alot! Thanks everyone.