Hi!

Just want to make system shutdown. For this goal I'm review grub sources.
And found few usefull functions:

prot_to_real:
    /* just in case, set GDT */
    lgdt    gdtdesc

    /* save the protected mode stack */
    movl    %esp, %eax
    movl    %eax, protstack

    /* get the return address */
    movl    (%esp), %eax
    movl    %eax, GRUB_MEMORY_MACHINE_REAL_STACK

    /* set up new stack */
    movl    $GRUB_MEMORY_MACHINE_REAL_STACK, %eax
    movl    %eax, %esp
    movl    %eax, %ebp

    /* set up segment limits */
    movw    $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax
    movw    %ax, %ds
    movw    %ax, %es
    movw    %ax, %fs
    movw    %ax, %gs
    movw    %ax, %ss

    /* this might be an extra step */
    /* jump to a 16 bit segment */
    ljmp    $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg

tmpcseg:
    .code16

    /* clear the PE bit of CR0 */
    movl    %cr0, %eax
    andl     $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax
    movl    %eax, %cr0

    /* flush prefetch queue, reload %cs */
    DATA32    ljmp    $0, $realcseg

realcseg:
    /* we are in real mode now
     * set up the real mode segment registers : DS, SS, ES
     */
    /* zero %eax */
    xorl    %eax, %eax

    movw    %ax, %ds
    movw    %ax, %es
    movw    %ax, %fs
    movw    %ax, %gs
    movw    %ax, %ss

    /* restore interrupts */
    sti

    /* return on new stack! */
    DATA32    ret

    .code32
------------------------------------------------------------------------
FUNCTION(grub_halt)
    /* see if zero */
    testl    %eax, %eax
    jnz    EXT_C(grub_stop)

    call    prot_to_real
    .code16

    /* detect APM */
    movw    $0x5300, %ax
    xorw    %bx, %bx
    int    $0x15
    jc    EXT_C(grub_hard_stop)
    /* don't check %bx for buggy BIOSes... */

    /* disconnect APM first */
    movw    $0x5304, %ax
    xorw    %bx, %bx
    int    $0x15

    /* connect APM */
    movw    $0x5301, %ax
    xorw    %bx, %bx
    int    $0x15
    jc    EXT_C(grub_hard_stop)

    /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
    movw    $0x530E, %ax
    xorw    %bx, %bx
    movw    $0x0101, %cx
    int    $0x15
    jc    EXT_C(grub_hard_stop)

    /* set the power state to off */
    movw    $0x5307, %ax
    movw    $1, %bx
    movw    $3, %cx
    int    $0x15

    /* shouldn't reach here */
    jmp    EXT_C(grub_hard_stop)
    .code32

When I'm trying switch to real mode - as result system goes down. Need some
explanation why. Tnx.

Best regards, Taras.

Attachment: poweroff.patch
Description: Binary data

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
SharpOS-Developers mailing list
SharpOS-Developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sharpos-developers

Reply via email to