summaryrefslogtreecommitdiff
path: root/src/boot/stage2_check_magic.asm
blob: 1deaf052d3608235a48341dc30c51d551df312ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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