How To Build An Operating System: User Modes- Part 06

User Mode

Loading an External Program

GRUB Modules

module /modules/program
mkdir -p iso/modules
MAGIC_NUMBER  equ 0x1BADB002      ; define the magic number constant
ALIGN_MODULES equ 0x00000001 ; tell GRUB to align modules

; calculate the checksum (all options + checksum should equal 0)
CHECKSUM equ -(MAGIC_NUMBER + ALIGN_MODULES)

section .text: ; start of the text (code) section
align 4 ; the code must be 4 byte aligned
dd MAGIC_NUMBER ; write the magic number
dd ALIGN_MODULES ; write the align modules instruction
dd CHECKSUM ; write the checksum

Executing a Program

Finding the Program in Memory

int kmain(/* additional arguments */ unsigned int ebx)
{
multiboot_info_t *mbinfo = (multiboot_info_t *) ebx;
unsigned int address_of_module = mbinfo->mods_addr;
}
typedef void (*call_module_t)(void);
call_module_t start_program = (call_module_t) address_of_module;
start_program();
/* we'll never get here, unless the module code returns */

--

--

--

Software Engineering Undergraduate at University of Kelaniya

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Look at the Holo Hosting Infrastructure

WebXR: SVG to glTF pipeline

These Are the 10 Best Lesser-Known Python Libraries You Should Know About

I wrote a programming language. Here’s how you can, too.

Flutter Vs React Native: Choose Your Framework

Logo

A tech startup pragmatic approach to scale, speed, and cost.

My go-to stack to reduce side-projects costs

A laptop with an open code editor.

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
Pubudu Wickramathunge

Pubudu Wickramathunge

Software Engineering Undergraduate at University of Kelaniya

More from Medium

Distributed Tracing in Polyglot Microservices

Fantastic Symbols and Where to Find Them — Part 1

Priority Queue — [Introduction to Algorithms]

How to give “Upload Only” permissions to S3 users using IAM