我试图按照这里的说明构建一个简单的操作系统内核:http://mikeos.sourceforge.net/write-your-own-os.html
除了从软盘启动,我想创建一个基于grub的ISO映像并在模拟器中启动多重启动CD.对于多引导头,我已将以下内容添加到该页面上列出的源:
MBALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MBALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
Run Code Online (Sandbox Code Playgroud)
我正在做以下事情来创建图像:
nasm -felf32 -o init.bin init.s
cp init.bin target/boot/init.bin
grub2-mkrescue -o …Run Code Online (Sandbox Code Playgroud) 我正在开发一个简单的内核,并且一直在尝试实现一个键盘中断处理程序来摆脱端口轮询。我一直在-kernel模式下使用 QEMU (为了减少编译时间,因为使用生成 isogrub-mkrescue需要相当长的时间)并且它工作得很好,但是当我想切换到-cdrom模式时它突然开始崩溃。我不知道为什么。
最终我意识到,当它从 ISO 引导时,它还会在引导内核本身之前运行 GRUB 引导加载程序。我发现 GRUB 可能会将处理器切换到保护模式,这会导致问题。
问题:通常我会简单地初始化中断处理程序,每当我按下一个键时,它就会被处理。但是,当我使用 iso 运行内核并按下一个键时,虚拟机就崩溃了。这发生在 qemu 和 VMWare 中,所以我认为我的中断一定有问题。
请记住,只要我不使用 GRUB,代码就可以正常工作。
interrupts_init()(见下文)是main()内核函数中调用的第一件事。
本质上的问题是:有没有办法让它在保护模式下工作?.
我的内核的完整副本可以在我的GitHub 存储库中找到。一些相关文件:
lowlevel.asm:
section .text
global keyboard_handler_int
global load_idt
extern keyboard_handler
keyboard_handler_int:
pushad
cld
call keyboard_handler
popad
iretd
load_idt:
mov edx, [esp + 4]
lidt [edx]
sti
ret
Run Code Online (Sandbox Code Playgroud)
interrupts.c:
#include <assembly.h> // defines inb() and outb()
#define IDT_SIZE 256
#define …Run Code Online (Sandbox Code Playgroud) 我正在写一个小操作系统作为学校分配的一部分,但是当我得到键盘输入时我被卡住了(按键 - >在屏幕上显示它).我正在使用osdev.org的bare Bones教程(gcc交叉编译器,GRUB引导程序,ld链接器),因为我处于保护模式,所以我不能使用BIOS中断进行输入,这就是为什么我必须编写自己的中断处理程序( ?)但即使在我阅读了一些osdev文章和论坛讨论后,我也不确定该怎么做.非常相似的问题(http://forum.osdev.org/viewtopic.php?f=1&t=9746),除了我不知道如何"设置中断".
#if !defined(__cplusplus)
#include <stdbool.h> /* C doesn't have booleans by default. */
#endif
#include <stddef.h>
#include <stdint.h>
#define INT_DISABLE 0
#define INT_ENABLE 0x200
#define PIC1 0x20
#define PIC2 0xA0
#define ICW1 0x11
#define ICW4 0x01
void outb( unsigned short port, unsigned char val )
{
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) );
}
static __inline unsigned char inb (unsigned short int port)
{
unsigned char _v;
__asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" …Run Code Online (Sandbox Code Playgroud) 我想将用户输入的号码输入寄存器。这是我自己的操作系统。所以,我不能使用这个:
mov al,0x01
int 0x21
mov dl,al ;move the integer entered by the user, into dl
Run Code Online (Sandbox Code Playgroud)
因为 int 0x21 调用 ms-dos。那么我可以使用什么中断呢?