C 16位内核有错误
现在已经有一段时间了,我正在处理操作系统和开发。因此,我开始在windows中使用MinGW编译器(GCC)进行一个项目。在跳转到保护模式之前,我想先创建一个16位操作系统和一个迷你DOS。我开始是为了它的发展。一切都进行得很顺利,但当我第一次在Boschs编译和执行操作系统时,发生了一件非常令人惊讶的事情。我试图打印欢迎使用我的操作系统,并使用shell样式从用户那里获取一些输入,但在屏幕上没有显示文本,只有光标在闪烁。我很困惑为什么会发生这样的事情,我查看了代码,发现有bug,我修复了它们并重新尝试,但失败了。我终于需要帮助了 我用的是什么C 16位内核有错误,c,windows,gcc,operating-system,kernel,C,Windows,Gcc,Operating System,Kernel,现在已经有一段时间了,我正在处理操作系统和开发。因此,我开始在windows中使用MinGW编译器(GCC)进行一个项目。在跳转到保护模式之前,我想先创建一个16位操作系统和一个迷你DOS。我开始是为了它的发展。一切都进行得很顺利,但当我第一次在Boschs编译和执行操作系统时,发生了一件非常令人惊讶的事情。我试图打印欢迎使用我的操作系统,并使用shell样式从用户那里获取一些输入,但在屏幕上没有显示文本,只有光标在闪烁。我很困惑为什么会发生这样的事情,我查看了代码,发现有bug,我修复了它们并
感谢所有帮助我解决此问题的用户。不要编写16位内核代码。你会受到很多限制。还请注意,您使用的是一个32位编译器。@BasileStarynkevitch-Sokrates-starynkewicz这里的链接显示了一个16位内核。正如您在我的主页上看到的,Sokrates-Starynkevitch是我的祖先…@user43609,链接器脚本
NUL
包含哪些内容?
asm(".code16 \n");
int strlen(const char *str)
{
int cnt = 0;
while(str[cnt] != 0)
{
cnt++;
}
return cnt;
}
void printChar(char ch)
{
asm volatile ("mov ah , 0x0e");
asm volatile ("mov al , %0" : : "r" (ch));
asm volatile ("int 0x10");
}
void printf(const char *str)
{
int len = strlen(str);
int cnt = 0;
while(cnt < len)
{
printChar(str[cnt]);
}
}
void kmain( )
{
printf("Welcome to My Operating System!");
jmp:
// Hang.
goto jmp;
}
[org 0x7c00] ;
[bits 16] ;
mov [boot_drive] , dl ;
mov bp , 0x9000 ;
mov sp , bp ;
mov bx , miniOS_booting ;
call print_string ;
call delay ;
call newline ;
mov bx , miniOS_bootdone ;
call print_string ;
call delay ;
mov bx , 0x1000 ;
mov dh , 1 ;
mov dl , [boot_drive] ;
call disk_load ;
mov ah , 0x0 ;
mov al , 0x2 ;
int 0x10 ;
jmp 0000:0x1000 ;
jmp $ ;
disk_load:
mov ah , 2 ; Read Sector Function
mov al , dh ; Number of sectors to read
mov dh , 0 ; Head
mov ch , 0 ; Track / Cylinder
mov cl , 2 ; Start From
int 0x13 ;
jc disk_error ;
ret ;
disk_error:
call newline ;
mov bx , miniOS_boot_error ;
call print_string ;
jmp $ ;
newline:
pusha;
mov ah , 0x0e ;
mov al , 10 ;
int 0x10 ;
mov al , 13 ;
int 0x10 ;
popa ;
ret ;
print_string:
pusha;
mov ah, 0x0e ;
pnt:
mov al , [bx] ;
cmp al , 0 ;
je done ;
int 0x10 ;
add bx , 1;
jmp pnt ;
done:
popa;
ret;
delay:
MOV CX, 0FH
MOV DX, 4240H
MOV AH, 86H
INT 15H
ret ;
miniOS_booting:
db 'Booting Mini OS .' , 0 ;
miniOS_bootdone:
db 'Booting Done .' , 0 ;
miniOS_boot_error:
db 'Error Booting.' , 0 ;
boot_drive:
db 0 ;
times 510 - ($ - $$) db 0;
dw 0xaa55 ;
[bits 16]
[extern _kmain]
___main:
call _kmain ;
jmp $ ;
nasm -f bin Boot.asm -o Boot.bin
nasm -f elf Entry.asm -o Entry.o
gcc -ffreestanding -c Kernel.c -o Kernel.o -masm=intel
ld -T NUL -Ttext 0x1000 -o Kernel.tmp Entry.o Kernel.o
objcopy -O binary -j .text Kernel.tmp Kernel.bin
copy /b Boot.bin+Kernel.bin OS
floppya : 1_44 = OS , status = inserted
boot : a