【发布时间】: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。 -
大概你的
data是char所以编译器使用%al。如果你有你的汇编文件,为什么要使用 C 内联 asm?