diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-10 20:55:56 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-10 20:55:56 +0200 |
commit | eea5bf4b859eb56c5772c58ca54937a90a10e7ee (patch) | |
tree | 391b31a28a3740d3fd52a9a9d1c651bc9f12cc2b /src/boot/stage2_check_magic.asm | |
parent | 1625a4752545e54c439a38f3393ab9d72bfee721 (diff) | |
download | abaos-eea5bf4b859eb56c5772c58ca54937a90a10e7ee.tar.gz abaos-eea5bf4b859eb56c5772c58ca54937a90a10e7ee.tar.bz2 |
moved bootloader to subdirectory
Diffstat (limited to 'src/boot/stage2_check_magic.asm')
-rw-r--r-- | src/boot/stage2_check_magic.asm | 48 |
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 |