尝试在 Assembly 和 C 中关闭时机器崩溃

Machine crashes when trying to shutdown in Assembly and C

我创建了一个关闭计算机的程序集文件,以及一些 C 代码。当我尝试与 ld 链接时。有效 另外,这是执行此操作的代码:

# set flags to 0
.set FLAGS,    0

# set magic number to 0x1BADB002 to identified by bootloader 
.set MAGIC,    0x1BADB002

# set the checksum
.set CHECKSUM, -(MAGIC + FLAGS)

# set multiboot enabled
.section .multiboot

# define type to long for each data defined as above
.long MAGIC
.long FLAGS
.long CHECKSUM


# set the stack bottom 
stackBottom:

# define the maximum size of stack to 512 bytes
.skip 4096


# set the stack top which grows from higher to lower
stackTop:

.section .text
.global _start
.type _start, @function

shutdown:
  mov %ax, 0x1000
  mov %ax, %ss
  mov %sp, 0xf000
  mov %ax, 0x5307
  mov %bx, 0x0001
  mov %cx, 0x0003
  int [=10=]x15

  ret

_start:

  # assign current stack pointer location to stackTop
    mov $stackTop, %esp

  # call the kernel main function
    call kernel_entry
    call shutdown

    cli


# put system in infinite loop
hltLoop:

    hlt
    jmp hltLoop

.size _start, . - _start





当我在 Virtualbox 中尝试时,它是这样说的:
在 QEMU 中,机器崩溃并重新启动。
有什么方法可以正确无误地关闭 OS 电源吗?如有任何帮助,我们将不胜感激。

我找到了一种以特定于模拟器的方式来完成它的方法。感谢 Jester 帮助我!