Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I am new to this forum. I have a doubt in bootloader written in NASM, the below ASM code working fine after comment the line "SECTION .data align=16", let me know the reason please...
[ORG 0]
jmp 07C0h:start ; initialize CS:IP values (go to code segment 0x07C0)
SECTION .text
start:
; Update the segment registers
mov ax, 0x7C0 ; 0x7C0 is code segment address, same initiated to other registers
mov ds, ax
mov es, ax
mov ss, ax
mov si, hello ; print hello string on the screen
cld ; clear direction flag (set DF = 0) to increment SI register
.l1:
lodsb ; load [SI] contents in to AL register and increment SI = SI + 1
cmp al, 0 ; compare 0 (null) is received
je .l2
mov ah, 0Eh
int 10h
jmp .l1 ; continue to lable 'lbl_1'
.l2:
SECTION .data align=16
hello db 'Welcome hello world', 0
times 510-($-$$) db 0
dw 0AA55h
The size of a bootsector is 512 bytes and is loaded by the BIOS at address 0x7C00. The two last bytes of this bootsector (at offset 0x7DFE) should contain the value 0xAA55. If the BIOS doesn't find this value, it shows an error message or it tries to boot from another disk. In your bootloader, you define a ".data" section. So, the size of your bootsector is 544 bytes (32 bytes for the ".text" section and 512 bytes for ".data") and the value 0xAA55 is located at 0x7E1E. That's why your code doesn't work.
Cheers,
Tommy
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
The size of a bootsector is 512 bytes and is loaded by the BIOS at address 0x7C00. The two last bytes of this bootsector (at offset 0x7DFE) should contain the value 0xAA55. If the BIOS doesn't find this value, it shows an error message or it tries to boot from another disk. In your bootloader, you define a ".data" section. So, the size of your bootsector is 544 bytes (32 bytes for the ".text" section and 512 bytes for ".data") and the value 0xAA55 is located at 0x7E1E. That's why your code doesn't work.
Cheers,
Tommy
Yes you are right.
Hi, I have used the below command to generate a image file
when you give the following line
SECTION .data align=16
the '$$' indicate the start of data section.
the '$' define current offset relative to [org]
thus,
510 - ($-$$) = 510 - ( 0x32 - 0x20 ) = 510 - 0x12 = 492
osdevkid wrote:[
since code segment is very small, why data segment goes beyound 512 bytes?
I have also one question: why you really want to add a .data segment? It is useless and your bootloader
works if your remove that line, as indicated in your first post.
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
shahadat wrote:each time you define a section, '$' and '$$' gets redifined.
Thank you very much "shahadat".
So we can save the '$' & '$$' values in some register, before move to next segment, at last we can calculate the exact bytes required to fill zeros, is it possible ?
osdevkid wrote:[
since code segment is very small, why data segment goes beyound 512 bytes?
I have also one question: why you really want to add a .data segment? It is useless and your bootloader
works if your remove that line, as indicated in your first post.
Hi "f2" thank you very much for your post.
Leave about the bootloader, when we move from one segment to another segment,
1) '$', '$$' are redefined, so my calculation is not perfect. How to make it perfect?
2) At particular offset I want to write some data, in a normal application (with segments), How to do it.
You posted 11 questions in three threads in less than 4 hours. Have you read the manual, especially when keeping our comments in mind?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Combuster wrote:You posted 11 questions in three threads in less than 4 hours. Have you read the manual, especially when keeping our comments in mind?
Yes, I read the manual and exerciesed programs. Still I have lot of questions in my mind, first I am doing google, if I cant able to find the answer, then I come here.
Manuals are good and common for all, but when we encounter specific problems, FORUMS are best place to clarify them.
osdevkid wrote:Yes, I read the manual and exerciesed programs. Still I have lot of questions in my mind, first I am doing google, if I cant able to find the answer, then I come here.
Manuals are good and common for all, but when we encounter specific problems, FORUMS are best place to clarify them.
especially comments from experts like you.
Yes, well...
This is a forum about OS development.
There is some consensus that you shouldn't try to do OS development in a language you are not fluent in. You should first get familiar with your language of choice in writing "normal" (user space) programs.
Which means beginner ASM questions are somewhat misplaced here, and should rather go to some general ASM programming forum.
Sure you can go ask an Indy Car driver or a Rallye driver to teach you how to drive. He might even do it, out of general generosity. But you'd be better off talking to a driving instructor.
Every good solution is obvious once you've found it.