Reputation: 285
I am studying assembly language, I followed http://mikeos.berlios.de/write-your-own-os.html steps, for make a bootable graphic game, but I have a problem: I can't use more than 512 bytes of memory for my program.
How can I solve this problem?
I appreciate any help.
Here my code (still smaller than 512 bytes): http://pastebin.com/i6ehx8dT
Edit: I solve my problem, here a minimum example of floppy bootloader made in assembly language 16 bits: http://pastebin.com/x1SawyjN
Finally this link was very helpfully: http://www.nondot.org/sabre/os/files/Booting/nasmBoot.txt
Upvotes: 1
Views: 1748
Reputation: 3
Here is a simple bootloader that I have made:
[org 0x7c00]
; stack and segment setup
xor ax, ax
mov es, ax
mov ds, ax
mov bp, 0x1200 ; thank you user ecm for notifying me to not use
; 0x8000 as the stack address
mov ss, ax ; thank you user ecm for notifying me to add this specified line of code
mov sp, bp
; load more than 512 bytes into memory
mov ah, 0x02 ; read sectors
mov al, 0x01 ; sectors to read
mov ch, 0x00 ; cylinder idx
mov dh, 0x00 ; head idx
mov cl, 0x02 ; sector idx
mov dl, 0x00 ; disk idx
mov bx, program ; address of more than 512 bytes
int 0x13
; because i'm tired you can do the error checking by checking if al is the
; same as what you set it to and checking for the carry flag
; jump to program (no error checking!)
jmp program
times 510-($-$$) db 0
dw 0xAA55
; more than 512 bytes program
program:
mov ah, 0x0E
mov bh, 0x00
mov al, 'A'
int 0x10
jmp $
; amount of zeros = 512 + (number of sectors read * 512)
times 1024-($-$$) db 0
Upvotes: 0
Reputation: 18531
This is not easiely done:
In fact the BIOS only loads the first 512 bytes of the disk into memory.
What you have to do then is load the rest of the data into memory. This is typically done using interrupt 13h (sub-functions AH=2 or AH=42h).
If you exactly know where on the disk the data is located this is quite easy. For this reason boot loaders like GRUB use well-known locations - unfortunately such locations are sometimes overwritten by other programs like copy-protection drivers.
If you need to load from a well-defined file system (e.g. FAT or NTFS) this is more tricky: You have only ~450 bytes of space (because ~60 of the 512 bytes are used by the file system internally) for code that interprets the data of the file system, finds the file containing the code and loads it into memory!
Upvotes: 2