Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
96c3a990
authored
Sep 05, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added multi-stage bootloader that loads real bootloader from disk
parent
8b0face4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
30 deletions
boot.asm
boot.asm
View file @
96c3a990
;--------------- PRELIMINARY SETUP ---------------;
[
bits
16
]
; 16 bit real mode
[
BITS
16
]
; 16 bit real mode
[
org
0x7C00
]
; MBR is loaded at 0x7C00
[
ORG
0x7C00
]
; MBR is loaded at 0x7C00
jmp
0x0000
:
st
;cs=0x0000, for consistency
st
:
xor
ax
,
ax
;clearing registers
mov
ds
,
ax
mov
es
,
ax
mov
dl
,
0x80
; HDD1
xor
dh
,
dh
; force 0
mov
bx
,
0x7e00
; read to 7e00, after bootloader
mov
al
,
1
; num of sectors to read
mov
cx
,
0x0002
; floppy cylinder
call
read_sectors_16
; read with above args
jnc
0x7e00
; jump to actual code
halt
:
cli
; halt if failed, loop
hlt
jmp
halt
read_sectors_16
:
pusha
mov
si
,
0x02
; maximum attempts - 1
.
top
:
mov
ah
,
0x02
; read sectors into memory (int 0x13, ah = 0x02)
int
0x13
jnc
.
end
; exit if read succeeded
dec
si
; decrement remaining attempts
jc
.
end
; exit if maximum attempts exceeded
xor
ah
,
ah
; reset disk system (int 0x13, ah = 0x00)
int
0x13
jnc
.
top
; retry if reset succeeded, otherwise exit
.
end
:
popa
retn
read_fail
db
'
Failure
to
read
from
disk
.
'
,
13
,
10
,
0
; $ is current line, $$ is first line, db 0 is a 00000000 byte
; So, pad the code with 0s until you reach 510 bytes
times
510
-
(
$
-
$$
)
db
0
; Fill last two bytes (a word) with the MBR signature 0xAA55
dw
0xaa55
;---------------- BOOTLOADER CODE ----------------;
;---------------- BOOTLOADER CODE ----------------;
ls
:
MOV
SI
,
str1
; pointer to string in SI
ls
:
mov
si
,
str1
; pointer to string in si
CALL
PrintStr
; print string
call
PrintStr
; print string
;MOV ebx, 1000 ;start at 10000
jmp
Main
;
;SUB ebx, 1 ;down 1 each time
hlt
;NOP ;waste time
;JZ 6 ;for loop
;JMP ls ;
HLT
;---------------- SCREEN FUNCTIONS ---------------;
;---------------- SCREEN FUNCTIONS ---------------;
PrintStr
:
; print string at SI
PrintStr
:
; print string at SI
next
c
har
:
next
C
har
:
MOV
AL
,
[SI]
; G
rab next char
mov
al
,
[si]
; g
rab next char
OR
AL
,
AL
; if char is null term
or
al
,
al
; if char is null term
JZ
exit
; then return
jz
exit
; then return
CALL
PrintChar
; else print char
call
PrintChar
; else print char
INC
SI
; inc pointer to next char
inc
si
; inc pointer to next char
JMP
nextc
har
; loop
jmp
nextC
har
; loop
exit
:
exit
:
RET
ret
PrintChar
:
; print char at AL
PrintChar
:
; print char at AL
MOV
AH
,
0x0E
; Teletype M
ode
mov
ah
,
0x0e
; teletype m
ode
MOV
BH
,
0x00
; P
age zero
mov
bh
,
0x00
; p
age zero
MOV
BL
,
0x07
; Light G
ray
mov
bl
,
0x07
; light g
ray
INT
0x10
; Print C
haracter
int
0x10
; print c
haracter
RET
ret
;------------------ DATA BLOCK ------------------;
;------------------ DATA BLOCK ------------------;
str1
db
'
Hello
World
'
,
0
;stuff
str1
db
'
Hello
World
'
,
0
;stuff
;-------------- PADDING / SIGNATURE -------------;
str2
db
'
WHY
IS
THIS
'
,
0
; $ is current line, $$ is first line, db 0 is a 00000000 byte
; So, pad the code with 0s until you reach 510 bytes
TIMES
510
-
(
$
-
$$
)
DB
0
; Fill last two bytes (a word) with the MBR signature 0xAA55
DW
0xAA55
Main
:
;main section
Main
:
;main section
nop
nop
mov
si
,
str2
call
PrintStr
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment