现在,我正在处理操作系统和开发。 所以我开始在Windows中使用MinGW编译器(GCC)的项目。 我想在创build一个16位的操作系统和一个迷你的DOS之前跳到保护模式。 我开始了它的发展。 Everyteen进展顺利,但是当我第一次在博世编译和执行操作系统时,发生了一件非常惊人的事情。 我试图打印欢迎到我的操作系统,并从用户使用shell风格的一些input,但在屏幕上没有文字出来,只有光标闪烁。 我很困惑,为什么会出现这种情况,我低头看了看代码,发现有错误,我修复了它们,重新尝试了,但是失败了。 最后我需要帮助!
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
感谢所有的用户帮助我解决这个问题。