code16 text global start org start cli lss cs STKPTR sp sti call scanb

 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
.code16
.text
.global start
.org 0
start:
cli
lss %cs:STKPTR, %sp
sti
call scanbios
call stop
STKPTR: .word 0xFFFE,0x9000
BEGSEG: .word 0xC000
.long 0x55FFFFAA #checksum stub
ENDSEG: .word 0xF000
scanbios:
cld
mov BEGSEG, %bp
st:
mov %bp,%ds
mov $0x80,%di
cmpw $0xAA55,%ds:0
jnz skip
xorw %si, %si
xorw %cx, %cx
movb %ds:2, %ch
xorb %bl, %bl
movzbw %ch,%di
add $0x3, %di
and $0xFFFC, %di
shl $5,%di
1: lodsw
addb %ah, %al
addb %al, %bl
decw %cx
jnz 1b
or %bl, %bl
jnz skip
pusha
push %ds
push %es
push %fs
push %gs
push %cs
pushw $1f
push %ds
pushw $3
lret
1:
pop %gs
pop %fs
pop %es
pop %ds
popa
skip:
add %di,%bp
cmp $0xF000,%bp
jb st
ret
stop:
cli
hlt
jmp stop
#real startup entry begins at F000:FFF0
.section .ejump
.byte 0xEA
.word start
.word 0xF000
.org 0x0E
.word 0x99FC
.end start