diff --git a/Worksheet2/iso/boot/grub/menu.lst b/Worksheet2/iso/boot/grub/menu.lst deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Worksheet2/iso/boot/grub/stage2_eltorito b/Worksheet2/iso/boot/grub/stage2_eltorito deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Worksheet2/source/iso/boot/grub/menu.lst b/Worksheet2/source/iso/boot/grub/menu.lst new file mode 100644 index 0000000000000000000000000000000000000000..5ee35ea22659704ed7d10bcee3d4f148e2627860 --- /dev/null +++ b/Worksheet2/source/iso/boot/grub/menu.lst @@ -0,0 +1,5 @@ + default=0 + timeout=0 + + title os + kernel /boot/kernel.elf \ No newline at end of file diff --git a/Worksheet2/source/iso/boot/grub/stage2_eltorito b/Worksheet2/source/iso/boot/grub/stage2_eltorito new file mode 100644 index 0000000000000000000000000000000000000000..9e1617cee78bb8f1ab6838837c9a1f36d729c9fd Binary files /dev/null and b/Worksheet2/source/iso/boot/grub/stage2_eltorito differ diff --git a/Worksheet2/source/iso/boot/kernel.elf b/Worksheet2/source/iso/boot/kernel.elf new file mode 100755 index 0000000000000000000000000000000000000000..010dd73cde1155314f9d9901e86f53b5df6909a4 Binary files /dev/null and b/Worksheet2/source/iso/boot/kernel.elf differ diff --git a/Worksheet2/source/kernel.elf b/Worksheet2/source/kernel.elf index 18e16939683d0011afd371865e03a36acbf5329b..010dd73cde1155314f9d9901e86f53b5df6909a4 100755 Binary files a/Worksheet2/source/kernel.elf and b/Worksheet2/source/kernel.elf differ diff --git a/Worksheet2/source/link.ld b/Worksheet2/source/link.ld index a96d1b8b51bcaf1b1190f0e294d8a30643980018..4600a2841556a51183af44454cbd59e8360eb8b1 100644 --- a/Worksheet2/source/link.ld +++ b/Worksheet2/source/link.ld @@ -1,22 +1,26 @@ -ENTRY(loader) /* The entry point for the kernel */ +ENTRY(loader) /* the name of the entry label */ SECTIONS { - . = 0x00100000; /* Load the kernel code at 1 MB */ - - .text : { /* Text (code) section */ - *(.text) /* Include all text sections */ + . = 0x00100000; /* the code should be loaded at 1 MB */ + + .text ALIGN (0x1000) : /* align at 4 KB */ + { + *(.text) /* all text sections from all files */ } - - .rodata : { /* Read-only data section */ - *(.rodata*) /* Include all read-only data sections */ + + .rodata ALIGN (0x1000) : /* align at 4 KB */ + { + *(.rodata*) /* all read-only data sections from all files */ } - .data : { /* Data section */ - *(.data) /* Include all data sections */ + .data ALIGN (0x1000) : /* align at 4 KB */ + { + *(.data) /* all data sections from all files */ } - .bss : { /* BSS section */ - *(.bss) /* Include all BSS sections */ - *(COMMON) /* Include common sections */ + .bss ALIGN (0x1000) : /* align at 4 KB */ + { + *(COMMON) /* all COMMON sections from all files */ + *(.bss) /* all bss sections from all files */ } -} +} \ No newline at end of file diff --git a/Worksheet2/source/loader.asm b/Worksheet2/source/loader.asm deleted file mode 100644 index 8a95ce3a71efea801c60028b105d4b7299f4f4a5..0000000000000000000000000000000000000000 --- a/Worksheet2/source/loader.asm +++ /dev/null @@ -1,17 +0,0 @@ -global loader ; Entry point for the kernel - -section .text ; Start of the code section -MAGIC_NUMBER equ 0x1BADB002 ; Define the magic number constant -FLAGS equ 0x0 ; Multiboot flags -CHECKSUM equ -MAGIC_NUMBER ; Calculate the checksum - -; Align code at 4 bytes boundary - align 4 - dd MAGIC_NUMBER ; Magic number - dd FLAGS ; Flags - dd CHECKSUM ; Checksum - -loader: ; Entry point label - mov eax, 0xCAFEBABE ; Write 0xCAFEBABE to the eax register -.loop: - jmp .loop ; Loop forever diff --git a/Worksheet2/source/loader.o b/Worksheet2/source/loader.o index dfcbed2f3a4c859a2a16476a9016f153df56d614..96049ae8116950800a73c4056d1fbf91b18ad877 100644 Binary files a/Worksheet2/source/loader.o and b/Worksheet2/source/loader.o differ diff --git a/Worksheet2/source/loader.s b/Worksheet2/source/loader.s new file mode 100644 index 0000000000000000000000000000000000000000..450ba9b1cbbd3290b297c3dc20c34677092098a3 --- /dev/null +++ b/Worksheet2/source/loader.s @@ -0,0 +1,42 @@ +global loader ; the entry symbol for ELF + +MAGIC_NUMBER equ 0x1BADB002 ; define the magic number constant +FLAGS equ 0x0 ; multiboot flags +CHECKSUM equ -MAGIC_NUMBER ; calculate the checksum + ; (magic number + checksum + flags should equal 0) + +section .text ; start of the text (code) section +align 4 ; the code must be 4 byte aligned + dd MAGIC_NUMBER ; write the magic number to the machine code, + dd FLAGS ; the flags, + dd CHECKSUM ; and the checksum + +KERNEL_STACK_SIZE equ 4096 ; size of stack in bytes + +section .bss +align 4 ; align at 4 bytes +kernel_stack: ; label points to beginning of memory + resb KERNEL_STACK_SIZE ; reserve stack for the kernel + +section .text ; ensure all code is in .text +loader: ; the loader label (defined as entry point in linker script) + mov eax, 0xCAFEBABE ; place the number 0xCAFEBABE in the register eax + mov esp, kernel_stack + KERNEL_STACK_SIZE ; point esp to the start of the + ; stack (end of memory area) + + push dword 3 + push dword 2 + push dword 1 + call sum_of_three ; call the sum_of_three function + +.loop: + jmp .loop ; loop forever + +sum_of_three: + pop ebx ; Get first argument (this was pushed last) + pop ecx ; Get second argument + pop edx ; Get third argument + add eax, ebx ; Compute sum in eax + add eax, ecx + add eax, edx + ret ; Return diff --git a/Worksheet2/source/logQ.txt b/Worksheet2/source/logQ.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff43ca25c78faa4649fbf5107d16bac041bc76c1 Binary files /dev/null and b/Worksheet2/source/logQ.txt differ diff --git a/Worksheet2/source/os.iso b/Worksheet2/source/os.iso new file mode 100644 index 0000000000000000000000000000000000000000..94bd5284a8fa064680f09cd39d9d55052651506d Binary files /dev/null and b/Worksheet2/source/os.iso differ diff --git a/Worksheet2/source/stage2_eltorito b/Worksheet2/source/stage2_eltorito new file mode 100644 index 0000000000000000000000000000000000000000..3748c94bf5e8a9a58a07a6ddcfe94b87a4f0b95c Binary files /dev/null and b/Worksheet2/source/stage2_eltorito differ