diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-05-12 09:57:06 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-05-12 09:57:06 +0200 |
commit | 7b12df4784b9659cafe8cb52ced824dc9c2cd804 (patch) | |
tree | 6f8946e5deeec1c8cf06ab8829373cffb73091c4 /src | |
parent | e382b70880fe82176a086f909a027a2f85a884b6 (diff) | |
download | abaos-7b12df4784b9659cafe8cb52ced824dc9c2cd804.tar.gz abaos-7b12df4784b9659cafe8cb52ced824dc9c2cd804.tar.bz2 |
made magic signature check work
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.asm | 5 | ||||
-rw-r--r-- | src/stage2_functions.asm | 44 |
2 files changed, 40 insertions, 9 deletions
diff --git a/src/boot.asm b/src/boot.asm index 9b130a2..045b135 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -107,6 +107,10 @@ BEGIN_PROTECTED_MODE: ; check sanity of kernel by searching for MAGIC string at a given ; position call check_magic + mov edx, eax + call pm_print_hex + cmp ax, 1 + jnz HALT_OS ; print a message before we call the C level kernel mov si, MESSAGE_CALL_C_ENTRY @@ -117,6 +121,7 @@ BEGIN_PROTECTED_MODE: call c_entry ; "kernel halted" message, when we terminate the C kernel +HALT_OS: mov si, MESSAGE_HALTED call pm_print_string call pm_print_newline diff --git a/src/stage2_functions.asm b/src/stage2_functions.asm index d692ed2..0e95580 100644 --- a/src/stage2_functions.asm +++ b/src/stage2_functions.asm @@ -135,25 +135,51 @@ update_vga_cursor: pop ebx ret +; check whether the end of the loaded image contains in fact the magic +; string (avoid truncation of image) check_magic: - push eax 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 ecx, 0x7e00 ; offset of stage 2 - add ecx, eax - sub ecx, 11 ; the length of the magic string - mov dx, cx - call pm_print_hex - mov dx, [ecx] - call pm_print_hex + mov edx, 0x7e00 ; offset of stage 2 + 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 MAGIC_MISMATCH + jmp MAGIC_OK +MAGIC_MISMATCH: + mov si, MAGIC_OK_MSG + call pm_print_string + call pm_print_newline + xor eax, eax + jmp MAGIC_END +MAGIC_OK: + mov si, MAGIC_NOT_OK_MSG + call pm_print_string call pm_print_newline + xor eax, eax + mov eax, 1 +MAGIC_END: + pop edi pop esi pop edx pop ecx pop ebx - pop eax ret + +COMPARE_MAGIC: +db "ABAOSMAGIC", 0 +MAGICLEN equ $ - COMPARE_MAGIC + +MAGIC_NOT_OK_MSG: +db "Magic signature found", 0 + +MAGIC_OK_MSG: +db "Magic signature not found!", 0 |