ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Two question
1) Why doesn't this draw a diagnoal line? Is counter's register being curropted
2) For clobber section, do I need to define ax/eax if using ah/al?
nasm -f bin bootloader.S
cat bootloader line | dd of=/dev/fd0 bs=512
Code:
[BITS 16]
[ORG 0x7C00] ; Origin location
_start:
mov ah, 0x02 ; Read Disk Sectors
mov al, 0x03 ; Read three sector only (512 bytes per sector)
mov ch, 0x00 ; Track 0
mov cl, 0x02 ; Sector 2
mov dh, 0x00 ; Head 0
mov dl, 0x00 ; Drive 0 (Floppy 1) (This can be replaced with the value in BootDrv)
mov bx, 0x2000 ; Segment 0x2000
mov es, bx ; again remember segments bust be loaded from non immediate data
mov bx, 0x0000 ; Start of segment - offset value
.readsector:
int 0x13 ; Call BIOS Read Disk Sectors function
jc .readsector ; If there was an error, try again
mov ax, 0x2000 ; Set the data segment register
mov ds, ax ; to point to the kernel location in memory
jmp 0x2000:0x0000 ; Jump to the kernel
times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55 ; Boot loader signature
I see a problem...
The computer boots up in real mode (16 bit), but your program is
32bit. The CPU cant properly decode the instructions while it is in 16 bit
mode if the instructions it is given are encoded in 32bits.
Im guessing everything goes well until your bootloader puts the
kernel image into memory.
You have a few choices:
Write code in your bootloader that enters protected mode, then load your
kernel. Then you can use C 99% of the time. I think this would be overkill
for what you are doing though.
Write 16 bit real mode code, although you will have to write your code in
assembly. You can only access 1MB of memory, although that should be
enough.
Also, dont forget to set up a stack! Whether the stack pointer is valid or not
doest matter, it still needs to be at a known address in order to prevent
data overwrite.
1) can I still use inturprets in protected?(EDIT: HOW DO I USE VM86 mode?)
2) how do i set up a stack
3) whats the asm code for entering protected mode(probley can find it somewhere else too, so no worries)
1) Yes, if you couldnt use interupts then the computer would be useless and I dont know
how to use VM86 mode yet, sorry. There is information at the above address though.
2) Easy, since the the stack is addressed using ss:sp you need to set them to an appropriate address. Keep in mind the stack grows DOWN so dont set it too close
to other data. Here's an example.
movw $0x9000,%ax // set ax to 0x9000
movw %ax,%ss //set ss equal to ax (0x9000)
movw $0x8000,%sp // set sp to 0x8000, now the stack is at 9000:8000
You can set the stack to any address you wish, its your responsibility to make sure
data isnt overwritten by pushes and pops.
3) This page has info on protected mode, http://www.mega-tokyo.com/osfaq2/ind.../ProtectedMode
If you are going to do any kind of protected mode programming I suggest
downloading the intel programmers manual from intel's website.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.