Building your own Operating System (Week 06)

Loading an External Program

To load the code we want to execute into memory we will use a feature in GRUB called modules to load the program.

GRUB Modules

GRUB can load arbitrary files into memory from the ISO image, and these files are usually referred to as modules. To make GRUB load a module, add the following line at the end of the “menu.lst” file which is located in “iso/boot/grub/”.

module /modules/program
mkdir -p iso/modules

Executing a Program

A program written at this stage can only perform a few actions. Therefore, we need to store a very simple program in the “modules” directory. Here is a simple program for it.

nasm -f bin program.s -o program

Finding the Program in Memory

We must find where our program resides in memory which we can entirely do from C. We are going to pass the contents of “ebx” as an argument to “kmain”. To do it we need to create a header file called “multiboot.h”.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store