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/16 23:01] – [Pour aller plus loin] 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 128: | 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 175: | Line 176: | ||
qemu-system-i386 -enable-kvm -kernel kernel | qemu-system-i386 -enable-kvm -kernel kernel | ||
+ | | ||
+ | L' | ||
| | ||
==== Kernel en C ==== | ==== Kernel en C ==== | ||
Line 295: | Line 298: | ||
==== Booter son Kernel depuis un disque (sans GRUB) ==== | ==== Booter son Kernel depuis un disque (sans GRUB) ==== | ||
- | Pour booter son Kernel depuis un disque (// | + | Pour booter son Kernel depuis un disque (// |
+ | <code hello.s> | ||
+ | .code16 | ||
+ | .text # executable code location | ||
+ | | ||
- | <code> | + | _start: |
+ | |||
+ | # | ||
+ | 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 | ||
</ | </ | ||
- | Attention, dans ce cas précis... | + | 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 -o hello.o | ||
+ | ld --oformat=binary hello.o -o hello.bin | ||
+ | dd if=/ | ||
+ | dd if=hello.bin of=floppy.img | ||
+ | |||
+ | On peut facilement tester ce programme depuis son disque avec QEMU : | ||
+ | |||
+ | qemu-system-i386 -fda floppy.img -boot a # boot on floppy disk | ||
+ | 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 : | Pour aller plus loin : | ||
* http:// | * http:// | ||
- | * xxx | + | * http:// |
- | * xxx | + | * http:// |
Line 319: | Line 376: | ||
- | ==== Pour aller plus loin ==== | + | ==== Pour aller encore |
* http:// | * http:// |
archi/x86.1458169292.txt.gz · Last modified: 2024/03/18 15:05 (external edit)