【问题标题】:Machine crashes when trying to shutdown in Assembly and C尝试在 Assembly 和 C 中关闭时机器崩溃
【发布时间】:2020-09-15 21:50:59
【问题描述】:

我创建了一个关闭计算机的程序集文件以及一些 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 $0x15

  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 中,机器崩溃并重新启动。
有没有办法让我正确关闭操作系统而不会出现错误?任何帮助将不胜感激。

【问题讨论】:

  • 你不能在保护模式下使用int 0x15,我认为你是由于多重引导的东西。最简单的可能是切换回实模式,假设您没有破坏 IVT 和 BIOS 数据区。如果您只需要它在 virtualbox 中工作,那么有一个神奇的 i/o 端口(以及其他模拟器)。见osdev.org
  • 我试过 @Jester 但它说:错误:`%al' not allowed with outw
  • 这是怎么回事?
  • w 中的outw 表示单词%al 是一个字节。你想要%ax
  • 大概你的datachar 所以编译器使用%al。如果你有你的汇编文件,为什么要使用 C 内联 asm?

标签: assembly x86 kernel osdev


【解决方案1】:

我找到了一种以特定于模拟器的方式执行此操作的方法。感谢 Jester 帮助我!

【讨论】:

  • 这对以后的读者帮助不大;您的回答没有说​​明它实际上是如何完成的。回答你自己的问题很好,但只有一个真实的答案,而不仅仅是你如何解决它的模糊提示。例如如果其他人将其发布为对此问题的答案,我肯定会投反对票。 (我想你也会这样)。既然这是你自己的问题,我会很慷慨,不会马上投反对票。
猜你喜欢
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多