Frage

I'm fiddling around with the creation of an own bootloader (MBR). It's my first step into having a better understanding of operating systems.

My configuration is:

MacBook Air, OsX 10.8.4, Parallels Desktop, Xcode, XCode Command Line tools, Nasm, LD, gcc, ...

I have composed a boot loader:

;
;  FpLoader.s
;  

                bits    16                  ; 16-bit Real Mode
                org     0x7c00              ; Set origin to BIOS boot origin


;
; Bootloader entry-code
;
Main:           cli                         ; Enable interrupts
                mov     ax, cs              ; Setup stack segments
                mov     ds, ax
                mov     es, ax
                mov     ss, ax
                sti                         ; Enable interrupts

                mov     si, Message_1       ; Print string
                call PrintLn

                mov     si, Message_2       ; Print string
                call PrintLn

                call PrintCrLf
                call PrintCrLf

                call Reboot


;
; Read keypress
;
ReadKeypress:
                mov     ah, 0               ; BIOS function - Wait for and read keyboard
                int     0x16                ; Call BIOS Keyboard Service

                ret                         ; Return from procedure


;
; PrintLn string
;
PrintLn:
                lodsb                       ; Load [Si] in Al and increment Si

                or      al, al              ; Check if end of string reached (Al == 0)
                jz      .PrintLnEnd

                mov     ah, 0x0e            ; BIOS function - Print character on screen
                int     0x10                ; Call BIOS Screen Service

                jmp     PrintLn             ; Loop
.PrintLnEnd     call PrintCrLf


;
; Print Cr/Lf
PrintCrLf:      mov     ah, 0x0E            ; BIOS function - Print character on screen

                mov     al, 0x0D            ; Character to print: Cr
                int     0x10                ; Call BIOS Screen Service

                mov     al, 0x0A            ; Character to print: Lf
                int     0x10                ; Call BIOS Screen Service

                ret                         ; Return from procedure


;
; Reboot the machine
;
Reboot:         mov     si, AnyKey          ; Print string
                call PrintLn
                call ReadKeypress

                db      0x0ea               ; Sends us to the end of the memory causing reboot
                dw      0x0000
                dw      0xffff 


;
; Data
;
                ; Program data
Message_1       db "Hello World...", 0x0
Message_2       db "Painted Black bootloader.", 0x0
AnyKey          db "Press any key to reboot...", 0x0

                ; Filler bytes
                times 510 - ($-$$) db 0

                ; Trailer bytes
                dw 0xAA55                   ;Boot signature

I'm assembling this code with:

nasm -f bin FpLoader.s -o FpLoader.img
sudo dd if=FpLoader.img of=FpLoader.iso bs=2k

When I'm trying to start a Parallels Virtual Machine from FpLoader.iso, it refuses to start, telling me that it cannot boot from the iso (configured as a CD in the Parallels configuration).

Since I'm completely new to the topic, and puzzled on how to proceed with the tools I have available, I would appreciate any help you can give me.

I have found a number of partial solutions for Linux, Bochs, ... but nothing really pointed me in the right direction.

I'm not rigid about the Iso file. If someone can show me a way with an img file, a real bootable USB (within Parallels Virtual Machine), or some other solution (compatible with my configuration) for testing my developments, that would be fine as well.

Thanks in advance and kind regards, PB

War es hilfreich?

Lösung

To be more extensive on the solution i found (Using only Mac OSx and Parallels Desktop)

The boot loader, although the source (FpLoader.s) could be a bit more elegant (reserve a stack zone, set the sp, ...), is ok. The compilation can be done with:

   nasm -f bin FpLoader.s -o FpLoader.bin

This should give you a binary file of 512 bytes.

When using (eventually with sudo)

   dd if=FpLoader.bin of=FpLoader.iso bs=2k

an iso file of 512 bytes is created. This iso does not contain a second, nor following 'disk' sectors. I presume that the Parallels Desktop verification checks this and blocks the use of such an iso file.

So, we need an other solution: create an entire empty disk (floppy in this case) onto which we write the content of our binary file (in the first sector).

This can be done as follows:

dd if=/dev/zero of=FpLoader.img bs=1024 count=1440

diskutil eraseVolume MS-DOS FPLOADER `hdiutil attach -nomount FpLoader.img`

dd if=FpLoader.bin of=FpLoader.img bs=1 count=512 conv=notrunc"

The first command fills up an empty floppy image of 1.4 Mb, the second command overwrites the first sector with our boot loader.

Within Parallels Desktop One can create an Ms-Dos alike virtual machine with very little resources:

   Memory: 4 Mb
   Hard disk: 2 Gb
   Devices: Hard disk and Floppy disk (even Cd drive can be removed)

To be on the safe side, one can isolate the virtual machine from Mac (in the security settings). I had printscreens of the following three steps, but due to my still low reputation, I can't publish them. Sorry for that

The FpLoader.img can be connected to the Floppy drive.

And finally, the boot settings can be adjusted not to loose time scanning the Hard disk for boot sectors.

I hope this description gives enough information to get you starting if you want to develop an OS using a Mac and Parallels.

Kind regards, PB

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top