2 changed files with 79 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||||
|
as $1.s -o ../compile_folder/$2.o |
||||||
|
ld -Ttext 0x7c00 --oformat=binary ../compile_folder/$2.o -o ../compile_folder/$2.bin |
||||||
|
dd if=../compile_folder/$2.bin of=../compile_folder/$2.img |
@ -0,0 +1,76 @@ |
|||||||
|
#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" |
||||||
|
|
||||||
|
.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 |
||||||
|
|
||||||
|
#This goes first as to now overwrite %ah and %al. |
||||||
|
mov $0x00, %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 $0xFF, %bx #Offset into section |
||||||
|
int $0x13 # Low level disk services |
||||||
|
|
||||||
|
jnc notcarry |
||||||
|
mWriteString error |
||||||
|
jmp endcarrycheck |
||||||
|
|
||||||
|
notcarry: |
||||||
|
mWriteString succes |
||||||
|
#fallthrough |
||||||
|
|
||||||
|
endcarrycheck: |
||||||
|
|
||||||
|
mWriteString mystr |
||||||
|
|
||||||
|
mWriteString end |
||||||
|
|
||||||
|
# |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#move to 510th byte from the start and append boot signature |
||||||
|
. = _start + 510 |
||||||
|
.byte 0x55
|
||||||
|
.byte 0xaa
|
||||||
|
|
||||||
|
mystr: .asciz "asdf" |
||||||
|
|
||||||
|
. = _start + 1023 |
||||||
|
.byte 0x00
|
Loading…
Reference in new issue