![]() |
Why doesn't this work?
I'm working with FASM and essentially I'd just like the letter 'a' to appear from this boot loader code. I have no problems creating the disk or anything like that, but the code doesn't appear to work. Wondering if anyone can tell me what I'm doing wrong.
:
jmp 07c00h ; boot code start |
You should clear the (segment) registers first.
|
I believe that's what you were saying, but it doesn't appear to be working either.
:
mov ax, cs |
:
jmp 07c00h ; boot code start; off we go, unconditionally |
Yeah I realized that the jmp was branching me somewhere it wasn't supposed to, but removing that instruction as in the reply before yours, and messing with those registers as niteice suggested didn't work either. For some reason the code produces the correct output on one emulator. However, when I try to put it in the bootsector of a floppy image and boot it in Bochs no output is produced. With a modification of other code It does work and I honestly can't tell why. This is the modified code from the bootstrapper of MenuetOS and I just stripped it down so that it would only display MenuetOS on the screen.
:
boot_program equ 07c00h ;position for boot code |
Perhaps your boot isn't setting up the software interrupt vectors, whereas your emulator is. Perhaps your boot is switching you into a protected mode before you're ready. Again, there is little overall information here. Do you know what takes place during the booting process, or are you more or less copying something and trying to modify it?
|
Shouldn't you have [org 0x7c00] instead of manually jumping there? Seems like a fairly roundabout way of getting the desired effect, and it probably isn't even right.
|
Not sure whether you have to do it this way for an assignment for your school, otherwise I would use an existing bootloader like GRUB if you want to write an operating system - when you start with the bootloader, there's a big risk that you give up before you even started on the actual work ;).
|
DaWei
Here's what I understand about the boot process. After the power and motherboard perform the POST and the like. The computer searches the first sector (512 bytes at 0:0:1) of one of the I/O drives (be it a hard drive or floppy or CD or however else your BIOS specifies it). This segment of code which should terminate with the "magic number" 0x55AA. Is loaded into the RAM at location 0x7C00. From here execution begins based on whatever you had in that 512 bytes of code assuming of course it meets the "magic number" condition and it is in fact 512 bytes long. Both of these conditions are met in the code that I wrote as I understand it. These are the only two conditions I have to meet in as far as I know. The Bochs emulator is loading the boot sector of a floppy image. Which works based on the most recent code I posted. This code is just modified code from the MenuetOS bootstrapper 'cause I wanted to see if I could get something to work since obviously my code isn't working and I don't know why. Whatever that segment of code from MenuetOS is doing it makes the characters MenuetOS appear on the virtual monitor of the Bochs emulator, which means that if I took it onto an actual computer it would most likely work. However, my own code which should've just printed an 'a' character on the screen isn't working. Therefore, logically, the problem is my code and not the Bochs emulator. The copy and modify is only because I wanted to get something which would display so as not to grow discouraged. I'm actually hoping that I understand the boot process, at least after the POST test so that I can just code a simple bootstrapper which prints 'a' on the screen, and then I'll go further from there. One step at a time I hope. niteice The [org 0x7c00] directive only specifies where the programmer believes the actual program will be in memory. In this case I know (or I think I know rather) the program is being loaded into 7c00. In the MenuetOS code listed there that jmp instruction was actually followed by a series of data declarations. Hence, why the program jmps. However, those bytes weren't relevant to the printing of the characters 'MenuetOS'. Polyphemus_ The idea of an OS is cool, but I doubt I could ever get something like that working. More than anything I just want to display some text lol. This isn't for school, just satisfaction of my own curiosity and to see if I can grasp at any sort of "mastery" over assembly language. I realize that I can use assembly to program via the win32 api and all that other stuff, but I mean just nitty gritty fundamental stuff where here's the processor now do stuff with it with some limited inputs and outputs. Kinda like if I were programming a PIC microcontroller. I realize the levels of difficulty are very different, but I can control a stepper motor with a PIC lol. ----------------------------------- So let me see if I can redefine my question. Compare these two segements of code: MY CODE :
mov ah, 09h:
boot_program equ 07c00h ;position for boot codeMY CODE doesn't boot on a Bochs emulator. The MenuetOS code does boot on the Bochs emulator. What is the menuetOS code doing that I am not doing and therefore failing to create a primitive bootstrapper? Is there some procedure relevant to the boot process (once the boot sector has been loaded into memory) that I have failed to take into account/do in my own code? |
int 10h
That is a key thing. It amounts to an indirect call of some particular function, of which there are normally many. If your boot process is not setting those up, but the MenuetOS thing is, that's one significant difference. A number of those wind up calling functions that live in the BIOS, others call functions that have to be loaded into the system (such as the large number of MSDOS calls that were available after a system booted MSDOS). I have not looked under the hood in years, but those software interrupts used to live in the memory beginning at location 0 (real memory address). Each storage location was considered a vector. That is, it contained the address of some function to execute. One could replace the vector with one's own function address and then call the old vector when one's function was done. This was a way to chain in things like timer functions, TSR apps, etc. |
| All times are GMT -5. The time now is 9:19 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC