gcc gnu assembly kernel in real mode

我怕爱的太早我们不能终老 提交于 2020-01-07 06:47:20

问题


i am trying to build a 16bit kernel in gcc gnu assembly while my bootloader is written in pure assembly but i have trouble printing out strings while single character are okay:

Here is my bootloader.asm:

org 0x7c00
bits    16



    section .text
mov ax,0x1000
mov ss,ax
mov sp,0x000
mov esp,0xfffe



xor ax,ax
mov es,ax 
mov ds,ax


mov [bootdrive],dl


mov bh,0
mov bp,zeichen

mov ah,13h
mov bl,06h
mov al,1
mov cx,6
mov dh,010h
mov dl,01h

int 10h

load:
mov dl,[bootdrive]
xor ah,ah
int 13h
jc load

load2:
mov ax,0x1000
mov es,ax
xor bx,bx

mov ah,2
mov al,1
mov cx,2
xor dh,dh

mov dl,[bootdrive]
int 13h
jc load2


mov ax,0
mov es,ax

mov bh,0
mov bp,zeichen3

mov ah,13h
mov bl,06h
mov al,1
mov cx,13
mov dh,010h
mov dl,01h

int 10h

mov ax,0x1000
mov es,ax
mov ds,ax
jmp 0x1000:0x000

zeichen db  'hello2'
zeichen3 db 'soweit so gut'
bootdrive db 0
times   510 - ($-$$)    hlt
dw  0xaa55

and here my kernel.c:

asm("jmp main");


void  print()
{
    for(int i=0;i<5;i++)
    {
    asm("mov $0x0e,%ah");
    asm("mov $0x00,%bh");
    asm("mov %0,%%al":: "" ('g'));
    asm("int $0x10");
    }
}
void main()
{

    asm("mov    $0x1000,%eax;"
        "mov    %eax,%es;"
        "mov    %eax,%ds");
    const char string[]="hall0";
    print();
    for(int i=0;i<5;i++)
    {
        asm("mov $0x0e,%ah");
        asm("mov $0x00,%bh");
        asm("mov %0,%%al":: "" (string[i]));
        asm("int $0x10");
    }

    asm(".rept 512;"
        " hlt ;"
        ".endr");
}

the commands i use are: nasm -f bin -o bootloader.bin bootloader.asm and gcc kernel.c -c -o kernel.o -m16 -nostdlib -ffreestanding&&ld -melf_i386 kernel.o -o kernel.elf&&objcopy -O binary kernel.elf kernel.o&&cat bootloader.bin kernel.elf>myOS.bin&&qemu-system-i386 myOS.bin on my Linux Mint Cinnamon version 18. It prints out 10 g's after "soweit so gut" these are the 5 g's it should print plus the number of characters from "hall0" but i doesnt print "hall0". So i must have done something wrong in the bootloader.asm for the use of the gcc gnu assembler, maybe set up the stack wrong or something. Maybe someone can help me what to do?


回答1:


You have to compile the 'kernel.asm' to a bin file and then do the cat command



来源:https://stackoverflow.com/questions/41234695/gcc-gnu-assembly-kernel-in-real-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!