; 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, 0x8800 ; 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: xor esi, esi mov si, MAGIC_OK_MSG call pm_print_string call pm_print_hex shr edx, 16 call pm_print_hex call pm_print_newline xor eax, eax jmp .end .mismatch: xor esi, esi mov si, MAGIC_NOT_OK_MSG call pm_print_string call pm_print_hex shr edx, 16 call pm_print_hex 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 at ", 0 MAGIC_OK_MSG: db "Magic signature not found at ", 0