archi:x86
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| archi:x86 [2016/03/11 21:02] – [Bootloader] orel | archi:x86 [2024/03/18 15:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | * Compiler Explorer: https:// | ||
| ====Exemple Hello World en GAS ==== | ====Exemple Hello World en GAS ==== | ||
| Line 62: | Line 63: | ||
| </ | </ | ||
| - | ==== Bootloader ==== | + | ==== Bootloader |
| - | Considérons le code assembleur x86 suivant d'un // | + | Considérons le code assembleur x86 suivant d'un // |
| <code c boot.s> | <code c boot.s> | ||
| Line 102: | Line 103: | ||
| Pour aller plus loin : | Pour aller plus loin : | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| * https:// | * https:// | ||
| * http:// | * http:// | ||
| Line 127: | Line 129: | ||
| </ | </ | ||
| - | Lors de l' | + | Lors de l' |
| On peut aussi utiliser un //external linker script// pour compiler notre //kernel// : | On peut aussi utiliser un //external linker script// pour compiler notre //kernel// : | ||
| Line 174: | Line 176: | ||
| qemu-system-i386 -enable-kvm -kernel kernel | qemu-system-i386 -enable-kvm -kernel kernel | ||
| + | | ||
| + | L' | ||
| | | ||
| ==== Kernel en C ==== | ==== Kernel en C ==== | ||
| Line 292: | Line 296: | ||
| qemu-system-i386 -cdrom mykernel.iso | qemu-system-i386 -cdrom mykernel.iso | ||
| - | Chercher comment se passer de GRUB ? Un peu de lecture... | + | ==== Booter son Kernel depuis un disque (sans GRUB) ==== |
| - | * http://wiki.osdev.org/Bare_bones | + | Pour booter son Kernel depuis un disque (//floppy//, //hard disk// ou //usb disk//), il faut tout d' |
| - | * http://wiki.osdev.org/El-Torito | + | |
| - | | + | <code hello.s> |
| - | | + | .code16 |
| - | * http://wiki.osdev.org/Mkisofs | + | .text # executable code location |
| - | * http://wiki.osdev.org/Bootable_CD | + | |
| - | * http://stackoverflow.com/questions/34268518/creating-a-bootable-iso-image-with-custom-bootloader | + | |
| + | _start: # code entry point | ||
| + | |||
| + | # | ||
| + | movb $' | ||
| + | movb $0x0e, %ah | ||
| + | | ||
| + | |||
| + | # | ||
| + | movb $' | ||
| + | movb $0x0e, %ah | ||
| + | | ||
| + | |||
| + | # | ||
| + | movb $' | ||
| + | movb $0x0e, %ah | ||
| + | | ||
| + | |||
| + | # | ||
| + | movb $' | ||
| + | movb $0x0e, %ah | ||
| + | | ||
| + | |||
| + | # | ||
| + | movb $' | ||
| + | movb $0x0e, %ah | ||
| + | | ||
| + | |||
| + | hlt # halt | ||
| + | |||
| + | . = _start + 510 #mov to 510th byte from 0 pos | ||
| + | .byte 0x55 #append boot signature | ||
| + | .byte 0xaa #append boot signature | ||
| + | |||
| + | </code> | ||
| + | |||
| + | Attention, dans ce cas précis, le BIOS recopie en mémoire physique le secteur 0 (512 octets) et passe la main au CPU pour qu'il commence à exécuter en //mode real// (16 bits) les instructions au début du secteur 0... Notons que dans ce cas, il est possible de faire appel aux interruptions du BIOS pour écrire en mémoire VGA (//int 0x10//). | ||
| + | |||
| + | Il faut ensuite compiler ce programme //en flat binary// (et non en ELF) puis le copier sur sa disquette : | ||
| + | |||
| + | as hello.s | ||
| + | | ||
| + | dd if=/dev/zero of=floppy.img bs=512 count=2880 | ||
| + | dd if=hello.bin of=floppy.img | ||
| + | |||
| + | On peut facilement tester ce programme depuis son disque avec QEMU : | ||
| + | |||
| + | | ||
| + | qemu-system-i386 -hda floppy.img | ||
| + | |||
| + | On peut également mettre son bootloader sur le premier secteur d'une clef USB : /dev/sdc sur ma machine (fdisk -l). Mais, attention de ne pas se tromper au risque de perdre toutes vos données ! | ||
| + | |||
| + | cat hello.bin > /dev/sdc | ||
| + | |||
| + | Puis on reboote la " | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Pour aller plus loin : | ||
| + | * http://www.codeproject.com/Articles/ | ||
| + | * http://www.codeproject.com/Articles/ | ||
| + | * http://www.codeproject.com/Articles/737545/Writing-a-bit-dummy-kernel-in-C-Cplusplus | ||
| Line 311: | Line 376: | ||
| - | ==== Pour aller plus loin ==== | + | ==== Pour aller encore |
| - | * http:// | ||
| - | * http:// | ||
| - | * http:// | ||
| * http:// | * http:// | ||
| * http:// | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | |||
| + | |||
archi/x86.1457730146.txt.gz · Last modified: 2024/03/18 15:05 (external edit)
