从0开始制作一个简单的OS(bochs bios bximage)

 

1.      安装硬件环境模拟器bochs------------Ubuntu下源码安装bochs(裸机纯硬件)

 

Bochs是一个x86硬件平台的开源模拟器。它可以模拟各种硬件的配置。Bochs模拟的是整个PC平台,包括I/O设备、内存和BIOS。更为有趣的是,甚至可以不使用PC硬件来运行Bochs。通过改变配置,可以指定使用的CPU(386486或者586),以及内存大小等。Bochs是电脑里的“PC”。

 

安装编译工具和依赖库

bochs是由C++编写的,我们要安装相应的编译环境build-essential .如果要图形界面,安装xorg-dev.

sudo apt-get install build-essential

sudo apt-get install xorg-dev

sudo apt-get install libgtk2.0-dev

 

编译安装

$ apt-get sourcebochs //下载源码

$ cd bochs-2.5.1

$ ./configure  --enable-debugger  --enable-disasm

$ make

$ make install

NOTE:若出现not reference error,一般是因为没有在

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 C++ 编写一个完整的 STRING 类,该类能够对字符串进行各种操作,包括字符串拼接、查找、替换、截取、比较等。 下面是一个简单的 STRING 类的实现,可以进行基本的字符串操作: ```cpp #include <cstring> #include <iostream> using namespace std; class STRING { public: STRING(); // 构造函数 STRING(const char* str); // 构造函数,传入一个字符串 ~STRING(); // 析构函数 int length(); // 返回字符串长度 bool empty(); // 判断字符串是否为空 void clear(); // 清空字符串 void append(const char* str); // 在字符串后面添加一个字符串 void insert(int pos, const char* str); // 在指定位置插入一个字符串 void erase(int pos, int len); // 删除指定位置的字符 void replace(int pos, int len, const char* str); // 替换指定位置的字符 int find(const char* str, int pos); // 从指定位置开始查找一个字符串 const char* c_str(); // 返回字符串的指针 friend ostream& operator<<(ostream& os, const STRING& str); // 重载输出运算符 private: char* data; // 保存字符串的指针 int size; // 保存字符串的长度 }; // 构造函数:初始化字符串为空 STRING::STRING() { data = new char[1]; data[0] = '\0'; size = 0; } // 构造函数:将传入的字符串复制到新字符串中 STRING::STRING(const char* str) { if (str != nullptr) { size = strlen(str); data = new char[size + 1]; strcpy(data, str); } else { data = new char[1]; data[0] = '\0'; size = 0; } } // 析构函数 STRING::~STRING() { delete[] data; } // 返回字符串长度 int STRING::length() { return size; } // 判断字符串是否为空 bool STRING::empty() { return size == 0; } // 清空字符串 void STRING::clear() { delete[] data; data = new char[1]; data[0] = '\0'; size = 0; } // 在字符串后面添加一个字符串 void STRING::append(const char* str) { if (str == nullptr) { return; } int len = strlen(str); char* new_data = new char[size + len + 1]; strcpy(new_data, data); strcat(new_data, str); delete[] data; data = new_data; size += len; } // 在指定位置插入一个字符串 void STRING::insert(int pos, const char* str) { if (str == nullptr || pos > size || pos < 0) { return; } int len = strlen(str); char* new_data = new char[size + len + 1]; strncpy(new_data, data, pos); strncpy(new_data + pos, str, len); strcpy(new_data + pos + len, data + pos); delete[] data; data = new_data; size += len; } // 删除指定位置的字符 void STRING::erase(int pos, int len) { if (pos < 0 || pos >= size || len == 0) { return; } if (len > size - pos) { len = size - pos; } char* new_data = new char[size - len + 1]; strncpy(new_data, data, pos); strcpy(new_data + pos, data + pos + len); delete[] data; data = new_data; size -= len; } // 替换指定位置的字符 void STRING::replace(int pos, int len, const char* str) { if (str == nullptr || pos < 0 || pos >= size || len == 0) { return; } if (len > size - pos) { len = size - pos; } int new_size = size - len + strlen(str); char* new_data = new char[new_size + 1]; strncpy(new_data, data, pos); strcpy(new_data + pos, str); strcpy(new_data + pos + strlen(str), data + pos + len); delete[] data; data = new_data; size = new_size; } // 从指定位置开始查找一个字符串 int STRING::find(const char* str, int pos) { if (str == nullptr || pos < 0 || pos >= size) { return -1; } char* p = strstr(data + pos, str); if (p == nullptr) { return -1; } return p - data; } // 返回字符串的指针 const char* STRING::c_str() { return data; } // 重载输出运算符 ostream& operator<<(ostream& os, const STRING& str) { os << str.data; return os; } ``` 使用该类进行操作: ```cpp int main() { STRING str("hello world"); cout << str << endl; // 输出:"hello world" cout << str.length() << endl; // 输出:"11" cout << str.empty() << endl; // 输出:"0" str.clear(); cout << str << endl; // 输出:"" str.append("hello"); str.append(" world"); cout << str << endl; // 输出:"hello world" str.insert(5, ", everyone"); cout << str << endl; // 输出:"hello, everyone world" str.erase(5, 10); cout << str << endl; // 输出:"hello world" str.replace(5, 5, "everybody"); cout << str << endl; // 输出:"hello everybody" cout << str.find("every") << endl; // 输出:"6" return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值