开发者

calling shell from bootloader

I am making an OS from scratch. I ha开发者_运维问答ve made a hello world bootloader using the tutorials from the internet.

I am stuck at the next step though.

I need to call an executable ( basically my shell code from the ASM bootloader code ). I googled around and couldn't find anything substantial that was explained in a good way.

So, can someone help me connect my bootloader to the shell? A small snippet of code as an example would be great ( I understand better by code ). I promise, I would use that only to understand and not copy anything.

Thanks!


The part which goes between the bootloader and an application (such as a shell) is kind of... substantial. One could say that "making an OS from scratch" actually means writing that part, often called the kernel; compared to that, the bootloader is very small and simple.

Let's take Linux as example (on 32-bit x86). A Linux shell is a collection of x86 opcodes which expect to be loaded at a fixed address in RAM (that was chosen when the shell was compiled, or, more accurately, linked). The first job of the kernel is to setup the MMU so that the shell will have that view of the memory. The shell will communicate with the outside world by invoking the kernel, and it will do so through system calls. In Linux-x86, system calls use the int opcode (this triggers a software interrupt, and the system call arguments are conventionally passed in some of the registers). Some of the important system calls include the read and write calls: from the point of view of the shell, what you type on the keyboard can be read from a virtual file, indexed by a descriptor (an integer, with value 0 for "standard input"). The job of the kernel here is to accumulate key strokes (each will trigger a hardware interrupt, that the kernel receives -- the kernel is supposed to respond to hardware interrupts -- and translates into characters) and return them to the application when the application asks for them. Similarly, data written out by the shell on what the shell thinks of as "standard output" (descriptor 1) must be translated by the kernel into characters to be displayed, which implies talking to the video hardware.

A great resource of learning out to build an operating system is Minix. Minix was initially meant as a learning tool, described at length in Tannenbaum's book "Operating Systems Design and Implementation". It is opensource and free. Do yourself a favor, download Minix source code and buy the book (or borrow it from a library somewhere).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜