在通过汇编引导程序级别上执行的C程序 [英] Execute C program at bootloader level via Assembler

查看:169
本文介绍了在通过汇编引导程序级别上执行的C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个自定义的(很基本的Hello world!)bootloader的汇编,我想在执行C程序。请问C程序的工作,或由于不能丢失 stdio.h中文件?我怎么能启动加载到一个单一的.bin文件到 DD 捆绑一起的C程序到闪存驱动器/ CD?

I wrote a custom (VERY basic "Hello world!") bootloader in Assembler and I would like to execute a C program in that. Would the C program work, or fail due to a lost stdio.h file? And how could I bundle the C program along with the bootloader into a single .bin file to dd to a flash drive/CD?

推荐答案

我不知道你所说的失去 stdio.h中的意思,但很多C运行时功能,包括那些在 stdio.h中原型,使用系统调用来实现。如果没有操作系统运行,这些系统调用将无法正常工作。

I'm not sure what you mean by "lost stdio.h", but many C runtime functions, including those prototyped in stdio.h, are implemented using system calls. Without an OS running, those system calls won't work.

有可能写出运行没有安装操作系统,例如最常见的引导程序有汇编的只是一个很小的量,大多C code C code。关键是要避免使用运行时库。替代的系统调用,例如为显示,有BIOS调用和特定硬件的I / O。

It is possible to write C code that runs without an OS, for example most common bootloaders have just a tiny amount of assembler and mostly C code. The trick is to avoid using runtime libraries. Alternatives to syscalls, for e.g. display, are BIOS calls and hardware-specific I/O.

要举一个例子,除了动态分配,的fopen 在读模式下需要以下的低级别操作:

To take just one example, in addition to dynamic allocation, fopen in read mode needs the following low-level operations:


  • 从存储中读取数据块

  • 读取文件系统元数据(通常,超级块和根目录)

  • 处理文件系统元数据,找出文件内容存储

  • 创建包含足够的信息, FREAD 龟etc 找到磁盘上的数据
  • Reading a block of data from storage
  • Reading the file system metadata (often, superblock and root directory)
  • Processing file system metadata to find out where the file content is stored
  • Creating a FILE object that contains enough information for fread and fgetc to find the data on disk

您没有一个操作系统来帮助任何的是,你的C code将需要实现一个驱动器(可能是在调用BIOS)块的读取,并执行的其他步骤的行为。

You don't have an OS to help with any of that, your C code will need to implement a driver (possibly calling the BIOS) for block read, and implement the behavior of the other steps.

这篇关于在通过汇编引导程序级别上执行的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆