diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..10e371fc8769f607d4ca69e9fb4172eb740aa382 --- /dev/null +++ b/README.md @@ -0,0 +1,141 @@ +# UFCFWK‑15‑2 Operating Systems 2024: Worksheet 2 + +# README for Worksheet 2 - Tiny OS Development + +# Nguyen13.Minh@live.uwe.ac.uk - @nn3-minh + + +### Task 1: Booting the Machine +Objective: Create a bootable OS that writes 0xCAFEBABE to the EAX register. +Implementation: +``` + . + ├── drivers + ├── source + │ ├── loader.asm + │ ├── link.ld + ├── iso + │ ├── boot + │ │ ├── grub + │ │ │ ├── menu.lst + │ │ │ ├── stage2_eltorito + │ ├── kernel.elf + ├── Makefile + ├── README.md +``` + +--- +#### Assembly Code (loader.asm): +- **Assemble kernel**: +``` + global loader + + MAGIC_NUMBER equ 0x1BADB002 + FLAGS equ 0x0 + CHECKSUM equ -MAGIC_NUMBER + + section .text + align 4 + dd MAGIC_NUMBER + dd FLAGS + dd CHECKSUM + + loader: + mov eax, 0xCAFEBABE + .loop: + jmp .loop +``` +- **Linker Script (link.ld):**: +``` + ENTRY(loader) + SECTIONS { + . = 0x00100000; + .text ALIGN(0x1000) : { *(.text) } + .rodata ALIGN(0x1000) : { *(.rodata*) } + .data ALIGN(0x1000) : { *(.data) } + .bss ALIGN(0x1000) : { *(COMMON) *(.bss) } + } +``` +- **GRUB Configuration (menu.lst):**: +``` + default=0 + timeout=0 + title Tiny OS + kernel /boot/kernel.elf +``` +**Building the Kernel:** +Assemble and link: +``` + nasm -f elf loader.asm + ld -T source/link.ld -melf_i386 loader.o -o kernel.elf +``` +Create ISO image: +``` +genisoimage -R \ + -b boot/grub/stage2_eltorito \ + -no-emul-boot \ + -boot-load-size 4 \ + -A os \ + -input-charset utf8 \ + -quiet \ + -boot-info-table \ + -o os.iso \ + iso +``` +Run with QEMU: +``` +qemu-system-i386 -nographic -boot d -cdrom os.iso -m 32 -d cpu -D logQ.txt +``` + + +### Task 2: Calling C from Assembly +Objective: Extend the kernel to call C functions, including sum_of_three and two additional functions. + +#### Implementation: +- **CC Code Example (kernel.c):**: +``` + volatile int sum_of_three(int a, int b, int c) { + return a + b + c; + } + + volatile int multiply_two(int x, int y) { + return x * y; + } + + volatile int subtract(int x, int y) { + return x - y; + } +``` +- **Calling C from Assembly:Update loader.asm to:**: + ``` + extern sum_of_three + extern multiply_two + + loader: + push 3 + push 2 + push 1 + call sum_of_three + add esp, 12 + + mov eax, 5 + mov ebx, 6 + call multiply_two + .loop: + jmp .loop + ``` + +## Makefile Rules +**Commands:** +**Build the Kernel and ISO** +``` +make +``` +**Clean the Workspace** +``` +make clean +``` +**Run the OS in QEMU** +``` +make run +``` diff --git a/worksheet1/README.md b/worksheet1/README.md index 00dccc841011e7b7089f0c8db3f9987d3f2d392b..0c8c0d0817d8449ea854804533b91f3c29006fb5 100644 --- a/worksheet1/README.md +++ b/worksheet1/README.md @@ -1,4 +1,4 @@ -# UFCFWK‑15‑2 Operating Systems 2024: Worksheet 1 - An Echo of Assembler +# UFCFWK‑15‑2 Operating Systems 2024: Worksheet 1 # Worksheet 1 - An Echo of Assembler @@ -6,7 +6,7 @@ ## Introduction -This worksheet focuses on the implementation of assembler programs, use of external libraries, user input/output interaction, and handling of loops, conditions, and arrays. The following are details of tasks completed, with build instructions and their respective outputs. +This worksheet is focused on the implementation of programs using assemblers, external library usage, user input/output interaction, loop, conditions, and array handling. Below is a description of tasks completed together with build instructions and their output, respectively. ---