#include "types.h"#include "gdt.h"#include "interrupts.h"// 获取显示器的物理地址void printf(const char* str){static uint16_t* VideoMemory = (uint16_t*)0xb8000; // 改为staticstatic uint8_t x = 0, y = 0;// 取出低16位,高位不取for(int i=0; str[i]; i++){switch (str[i]){case '\n':y++; // 换行x = 0;break;default:VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0xFF00) | str[i];x++;break;}// 显示器的像素为 80*25if (x>=80) // 写满一行了{x = 0;y++;}if (y >= 25) // 写满屏了,清屏操作{for(y=0; y<25; y++) // 遍历每一行{for(x=0; x<80; x++) // 遍历每一列{VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0xFF00) | ' '; // 和 ' '字符或一下即可清空}}x = 0, y = 0;}}}typedef void (*constructor)();extern "C" constructor start_ctors;extern "C" constructor end_ctors;// 调用 constructor 函数extern "C" void callConstructors(){for(constructor* i=&start_ctors; i!=&end_ctors; i++){(*i)();}}extern "C" void kernelMain(void* multiboot_structure, uint32_t magicnumber){printf("hello world!\n");printf("cpp");GlobalDescriptorTable gdt;InterruptManager interrupts(0x20, &gdt); // 硬件偏移 0x20interrupts.Activate(); // 激活或开启中断while(1);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。