summaryrefslogtreecommitdiff
path: root/src/boot/stage2_check_magic.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/stage2_check_magic.asm')
-rw-r--r--src/boot/stage2_check_magic.asm48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/boot/stage2_check_magic.asm b/src/boot/stage2_check_magic.asm
new file mode 100644
index 0000000..1deaf05
--- /dev/null
+++ b/src/boot/stage2_check_magic.asm
@@ -0,0 +1,48 @@
+; check whether the end of the loaded image contains in fact the magic
+; string (avoid truncation of image)
+check_magic:
+ push ebx
+ push ecx
+ push edx
+ push esi
+ push edi
+ mov eax, NOF_LOAD_SECTORS ; number of 512-byte sectors
+ shl eax, 9 ; 512 bytes per sector
+ mov edx, 0x8400 ; offset of kernel
+ add edx, eax
+ sub edx, MAGICLEN ; subtract the length of the magic string
+ mov esi, edx ; now use edx as first string address to compare to
+ mov edi, COMPARE_MAGIC ; position of second string
+ mov ecx, MAGICLEN ; length of the magic string
+ repe cmpsb
+ jne .ok
+ jmp .mismatch
+.ok:
+ mov si, MAGIC_OK_MSG
+ call pm_print_string
+ call pm_print_newline
+ xor eax, eax
+ jmp .end
+.mismatch:
+ mov si, MAGIC_NOT_OK_MSG
+ call pm_print_string
+ call pm_print_newline
+ xor eax, eax
+ mov eax, 1
+.end:
+ pop edi
+ pop esi
+ pop edx
+ pop ecx
+ pop ebx
+ ret
+
+COMPARE_MAGIC:
+db "ABAOS", %[MAGIC], 0
+MAGICLEN equ $ - COMPARE_MAGIC
+
+MAGIC_NOT_OK_MSG:
+db "Magic signature found", 0
+
+MAGIC_OK_MSG:
+db "Magic signature not found!", 0