帮助建立一个16位的操作系统 [英] Help in building an 16 bit os

查看:184
本文介绍了帮助建立一个16位的操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的例子内核代码:



<$> p $ p> asm(。code16 \\\
);
void putchar(char);
int main()
{
putchar('A');
返回0;
}
void putchar(char val)
{
asm(movb%0,%% al\\\

movb $ 0x0E,%%啊\\\

int $ 0x10 \\\


:r(val)
);
}

这是我编译它的方式:

  nasm -f bin -o ./bin/boot.bin ./source/boot.asm 
gcc -nostdinc -fno-builtin -I./ include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext = 0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0
dd if = / dev / zero of =。/ bin / empty.bin bs = 1440K count = 1
cat ./bin/boot.bin ./bin/kernel.bin ./bin/empty.bin |头-c 1440K> ./bin/os
rm ./bin/empty.bin

我运行它在一个虚拟机中。



当我使用putchar函数(在内核代码中)获得常量值时.... ie就像这样:

  void putchar()
{
char val ='A';
asm(movb%0,%% al\\\

movb $ 0x0E,%% ah\\\

int $ 0x10\\\


:r(val)
);
}

然后它正常工作。但是当我将参数传递给它时(这是在前面的代码中),那么它为任何字符打印一个空格。
我应该怎么做?

解决方案

如果您想让gcc生成16位代码,您需要要使用 .code16gcc 而不是 .code16 ,以便获取函数参数的堆栈操作权限:请参阅在气体文档中写入16位代码



(另外,根据您使用的gcc版本,您可能需要编译 kernel.c code> -fno-unit-at-a-time 或 -fno-toplevel-reorder 选项,以确保 asm()伪指令在任何编译的代码之前确实遇到汇编程序 - 否则编译器可能会混淆东西。)


I am trying to build an old 16 bit DOS like OS.

My example kernel code:

    asm(".code16\n");
    void putchar(char);
    int main()
    {
    putchar('A');
    return 0;
    }
    void putchar(char val)
    {
       asm("movb %0, %%al\n"  
           "movb $0x0E, %%ah\n" 
           "int $0x10\n"
          :
          :"r"(val)
          ) ;
    }

This is how I compile it :

nasm -f bin -o ./bin/boot.bin ./source/boot.asm
gcc -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0
dd if=/dev/zero of=./bin/empty.bin bs=1440K count=1
cat ./bin/boot.bin ./bin/kernel.bin ./bin/empty.bin|head -c 1440K > ./bin/os
rm ./bin/empty.bin

and I run it in a virtual machine.

When I make the putchar function ( in kernel code ) for constant value ....i.e like this:

 void putchar()
 {
    char val = 'A';
    asm("movb %0, %%al\n" 
    "movb $0x0E, %%ah\n" 
    "int $0x10\n"
    :
    :"r"(val)
    ) ;
 }

then it works fine. But when I pass argument to it (That is in the previous code), then it prints a space for any character. What should I do?

解决方案

If you're trying to make gcc generate 16-bit code, you need to use .code16gcc rather than .code16, in order to get the stack manipulation right for function parameters: see "Writing 16-bit Code" in the gas documentation.

(Also, depending on which gcc version you're using, you may need to compile your kernel.c with either the -fno-unit-at-a-time or -fno-toplevel-reorder option, to ensure that the asm() directive really is encountered by the assembler before any compiled code - otherwise the compiler may shuffle things around.)

这篇关于帮助建立一个16位的操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆