Aide à la compréhension d'un code

mmaximum Messages postés 38 Date d'inscription jeudi 13 mars 2008 Statut Membre Dernière intervention 9 décembre 2011 - 9 juin 2008 à 18:03
cs_ghuysmans99 Messages postés 3982 Date d'inscription jeudi 14 juillet 2005 Statut Membre Dernière intervention 30 juin 2013 - 29 nov. 2008 à 17:00
Bonjour,
J'ai un code(ci-dessous) mais je n'ai jamais fais d'assembleur et je ne comprend pas tout.
Je connais le C,C++,python, et ca n'a pas l'aire de ressembler et je suis totalement perdu.
Ce code est extrait du loader de SOS(Simple Operating System).
Est-ce que quelqu'un pourrait m'expliquer ligne par ligne ce que ca fait?
Si jamais ca vous prend trop de temps, dites moi au moins un tutoriel pour apprendre l'assembleur.

/* Copyright (C) 1999  Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
   USA.
*/

   
/* The operating system is booted by Grub, so we almost have nothing
   to do to boot it. We only have to conform to the Multiboot
   standard, as defined by the Grub documentation */
   
#define ASM 1
/* The multiboot.h header contains a lot of multiboot standard
   definitions */
#include "multiboot.h"

    /* The multiboot header itself. It must come first. */
.section ".multiboot"
    /* Multiboot header must be aligned on a 4-byte boundary */
    .align 4
multiboot_header:
  /* magic=        */ .long MULTIBOOT_HEADER_MAGIC
  /* flags=        */ .long MULTIBOOT_HEADER_FLAGS
  /* checksum=     */ .long -(MULTIBOOT_HEADER_MAGIC \
                              +MULTIBOOT_HEADER_FLAGS)
  /* header_addr=  */ .long multiboot_header
  /* load_addr=    */ .long __b_kernel
  /* load_end_addr=*/ .long __e_load
  /* bss_end_addr= */ .long __e_kernel
  /* entry_addr=   */ .long multiboot_entry
   
/* Here is the beginning of the code of our operating system */
.text

.globl start, _start
start:
_start:
multiboot_entry:
    /* Set up a stack */
    movl $(stack + MULTIBOOT_STACK_SIZE), %ebp
    movl %ebp, %esp

    /* Set EFLAGS to 0 */
    pushl $0
    popf

    /* Push the magic and the address on the stack, so that they
    will be the parameters of the cmain function */
    pushl %ebx
    pushl %eax

    /* Call the cmain function (os.c) */
    call EXT_C(sos_main)

    /* Should never get there */
loop:
    hlt
    jmp loop

    /* Here is the stack */
.comm    stack, MULTIBOOT_STACK_SIZE

Merci d'avance, mmaximum

4 réponses

cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 2
11 juin 2008 à 16:16
salut,

ça met le registre ebp en sommet de pile (defini dans multiboot.h) , ça met le registre des flags a 0, ça push The Magic and the adresse on the stack puis ça appelle la fonction sos_main().

voilà,

@++
0
ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 3
9 sept. 2008 à 18:39
Salut,
Pour y voir clair , on doit connaître le format de fichier PE
http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
chercher magic dans le document et on voit mieux ce que le programme charge.
0
cs_ghuysmans99 Messages postés 3982 Date d'inscription jeudi 14 juillet 2005 Statut Membre Dernière intervention 30 juin 2013 16
29 nov. 2008 à 16:57
Euh pas d'accord.
Ce sont les specs de grub pour avoir un kernel multiboot
http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
0
cs_ghuysmans99 Messages postés 3982 Date d'inscription jeudi 14 juillet 2005 Statut Membre Dernière intervention 30 juin 2013 16
29 nov. 2008 à 17:00
Pour info, c'est le format ELF dans de cas.
0
Rejoignez-nous