summaryrefslogtreecommitdiff
path: root/src/boot/stage2_check_magic.asm
blob: 2e1a9d0e2cfefafe9199cbe2e0a5ba471e30c960 (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
49
50
51
52
53
54
55
56
; 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