1 changed files with 226 additions and 0 deletions
@ -0,0 +1,226 @@
|
||||
#generate 16-bit code |
||||
.code16 |
||||
|
||||
#hint the assembler that here is the executable code located |
||||
.text |
||||
.globl _start;
|
||||
#boot code entry |
||||
_start: |
||||
jmp _boot |
||||
start: .asciz "Start.\n\r" |
||||
error: .asciz "Error.\n\r" |
||||
succes: .asciz "Succes.\n\r" |
||||
ffs: .asciz "F.\n\r" |
||||
end: .asciz "End.\n\r" |
||||
derpy2str: .asciz "This is from derpy2.\n\r" |
||||
cookies: .word derpy2 |
||||
|
||||
.macro mWriteString str #macro which calls a function to print a string |
||||
leaw \str, %si |
||||
call .writeStringIn |
||||
.endm |
||||
|
||||
# function to print the string |
||||
.writeStringIn: |
||||
lodsb |
||||
orb %al, %al |
||||
jz .writeStringOut |
||||
movb $0x0e, %ah |
||||
int $0x10 |
||||
jmp .writeStringIn |
||||
.writeStringOut: |
||||
ret |
||||
|
||||
|
||||
_boot: |
||||
mWriteString start |
||||
|
||||
movb $0x0e, %ah |
||||
movb $'X', %al |
||||
int $0x10 |
||||
|
||||
movb $'\n', %al |
||||
int $0x10 |
||||
|
||||
movb $'\r', %al |
||||
int $0x10 |
||||
|
||||
lgdt gdtdesc |
||||
|
||||
#movb $42, %bl #NOT 'A' |
||||
#movb %bl, 0x512 |
||||
|
||||
#This goes first as to now overwrite %ah and %al. |
||||
mov $0x00, %ax |
||||
#mov $0x08, %ax |
||||
mov %ax, %es #Section to write into |
||||
|
||||
mov $0x02, %ah # Read sectors from drive |
||||
mov $0x01, %al # Number of sectors to read |
||||
mov $0x00, %ch # Low 8 bits of cylinder |
||||
mov $0x02, %cl # First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) |
||||
mov $0x00, %dh # Head number |
||||
mov $0x00, %dl # Drive number |
||||
# mov $0x00, %es |
||||
mov $0x7e00, %bx #Offset into section |
||||
#mov $0x0, %bx #Offset into section |
||||
int $0x13 # Low level disk services |
||||
|
||||
jnc notcarry |
||||
#mWriteString error |
||||
jmp endcarrycheck |
||||
|
||||
notcarry: |
||||
#mWriteString succes |
||||
|
||||
#mov $0x7000, %ax |
||||
#movb (%ax), %bl |
||||
#movb %bl, ffs |
||||
#movb 0x7000, %bl |
||||
#movb %bl, ffs |
||||
#mWriteString ffs |
||||
#fallthrough |
||||
|
||||
endcarrycheck: |
||||
|
||||
#mWriteString mystr-block2_offset |
||||
#mWriteString 0x513 |
||||
#mWriteString mystr |
||||
|
||||
#ljmp $0x0, $derpy |
||||
#.byte 0, 0, 0, 0, 0, 0, 0, 0 |
||||
#ljmp $0x00, $0x7e00 |
||||
#ljmp $0x00, $derpy2 |
||||
ljmp $0x00, $code |
||||
|
||||
# movw $derpy, %ax |
||||
#
|
||||
# cmp $0x7e00, %ax |
||||
# je equal |
||||
# mWriteString error |
||||
# jmp after |
||||
#
|
||||
# equal: |
||||
# mWriteString succes |
||||
#
|
||||
# after: |
||||
/* |
||||
movb $0x0e, %ah |
||||
|
||||
movw $derpy, %cx |
||||
|
||||
movb 0x0e, %ah |
||||
movb $'I', %al |
||||
int $0x10 |
||||
movb 0x0e, %ah |
||||
movb $'J', %al |
||||
int $0x10 |
||||
*/ |
||||
|
||||
#movw $0x7E00, %cx |
||||
movw $derpy2, %cx |
||||
|
||||
movb $0x0e, %ah |
||||
#movb $'Y', %al |
||||
movb %ch, %al |
||||
#movb $'H', %al |
||||
#movb $0x7E, %al |
||||
int $0x10 |
||||
|
||||
movb $0x0e, %ah |
||||
#movb $'Z', %al |
||||
movb %cl, %al |
||||
#add $0x7E, %al |
||||
#sub $0x50, %al |
||||
#movb $0x3C, %al |
||||
int $0x10 |
||||
|
||||
movb $0x0e, %ah |
||||
movb $'\n', %al |
||||
int $0x10 |
||||
|
||||
movb $0x0e, %ah |
||||
movb $'\r', %al |
||||
int $0x10 |
||||
|
||||
|
||||
#mWriteString mystr |
||||
|
||||
#jmp derpy |
||||
derpyret: |
||||
|
||||
mWriteString end |
||||
|
||||
#jmp 0x7008 |
||||
#endend: |
||||
#mWriteString end |
||||
|
||||
cli |
||||
hlt |
||||
|
||||
# |
||||
|
||||
derpy: |
||||
mWriteString ffs |
||||
ljmp $0x00, $derpyret |
||||
#jmp derpyret |
||||
|
||||
.p2align 2 /* force 4-byte alignment */ |
||||
gdt: |
||||
.word 0, 0 |
||||
.byte 0, 0, 0, 0 |
||||
|
||||
/* code segment */ |
||||
.word 0xFFFF, 0 |
||||
.byte 0, 0x9A, 0xCF, 0 |
||||
|
||||
/* data segment */ |
||||
.word 0xFFFF, 0 |
||||
.byte 0, 0x92, 0xCF, 0 |
||||
|
||||
/* 16 bit real mode CS */ |
||||
.word 0xFFFF, 0 |
||||
.byte 0, 0x9E, 0, 0 |
||||
|
||||
/* 16 bit real mode DS */ |
||||
.word 0xFFFF, 0 |
||||
.byte 0, 0x92, 0, 0 |
||||
|
||||
/* this is the GDT descriptor */ |
||||
gdtdesc: |
||||
.word 0x27 /* limit */ |
||||
.long gdt /* addr */ |
||||
|
||||
#move to 510th byte from the start and append boot signature |
||||
. = _start + 510 |
||||
.byte 0x55
|
||||
.byte 0xaa
|
||||
#block2_offset: |
||||
.byte 'A' #Byte 513 |
||||
#mystr: .asciz "asdf\n\r" |
||||
|
||||
#derpderp: |
||||
# mwriteString 0x7001 |
||||
# jmp endend |
||||
|
||||
derpy2: |
||||
mWriteString derpy2str |
||||
ljmp $0x00, $derpyret |
||||
|
||||
code: |
||||
mWriteString derpy2str |
||||
movb $0x0e, %ah |
||||
movb $'C', %al |
||||
int $0x10 |
||||
movb $0x0e, %ah |
||||
movb $'\n', %al |
||||
int $0x10 |
||||
movb $0x0e, %ah |
||||
movb $'\r', %al |
||||
int $0x10 |
||||
ljmp $0x00, $derpyret |
||||
|
||||
. = _start + 1021 |
||||
.byte 0x00
|
||||
|
||||
.word derpy2
|
Loading…
Reference in new issue