First commit
This commit is contained in:
commit
62e1d36c38
23 files changed
+2501
No files matched your search
Executable
+3
@@ -0,0 +1,3 @@
|
||||
as sing_boot_alt.s -o ../compile_folder/alt.o
|
||||
ld -Ttext 0x7c00 --oformat=binary ../compile_folder/alt.o -o ../compile_folder/sing.bin
|
||||
dd if=../compile_folder/sing.bin of=../compile_folder/sing.img
|
||||
Executable
+3
@@ -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,3 @@
|
||||
https://www.codeproject.com/Articles/664165/Writing-a-boot-loader-in-Assembly-and-C-Part
|
||||
|
||||
http://www.computer-engineering.org/index.html // keyboard and mouse programming
|
||||
@@ -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
|
||||
@@ -0,0 +1,227 @@
|
||||
#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 $(_start+0x200), %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
|
||||
@@ -0,0 +1,120 @@
|
||||
#generate 16-bit code
|
||||
.code16
|
||||
|
||||
#hint the assembler that here is the executable code located
|
||||
.text
|
||||
.globl _start;
|
||||
#boot code entry
|
||||
_start:
|
||||
jmp _boot #jump to boot code
|
||||
welcome: .asciz "Hello, new World\n\r" #here we define the string
|
||||
enter_number: .asciz "Enter a number: \n\r"
|
||||
lower_msg: .asciz "\nYour number is to low :( \n\r" # 26
|
||||
higher_msg: .asciz "\nYour number is to high :( \n\r" # 27
|
||||
winner_msg: .asciz "\nYour are the CAMPION, :D \n\r" # 26
|
||||
|
||||
.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
|
||||
|
||||
.type get_number, @function
|
||||
get_number:
|
||||
|
||||
# save state before function
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
push %bx
|
||||
push %cx
|
||||
# Start of function
|
||||
mWriteString enter_number
|
||||
|
||||
mov $0, %ah
|
||||
mov $0, %al
|
||||
int $0x16
|
||||
|
||||
mov $0x0E, %ah
|
||||
int $0x10
|
||||
|
||||
pop %cx
|
||||
pop %bx
|
||||
|
||||
mov %bp, %sp
|
||||
pop %bp
|
||||
ret
|
||||
|
||||
.type string_to_int, @function
|
||||
string_to_int:
|
||||
/* Converts a string to an integer. Returns the integer in %rax.
|
||||
* %rax: Address of string to convert.
|
||||
*/
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
push %bx
|
||||
push %cx
|
||||
|
||||
mov %ax, %dx
|
||||
|
||||
cmp $47, %dx
|
||||
jl not_a_num
|
||||
cmp $57, %dx
|
||||
jg not_a_num
|
||||
# I multiply by 10 to shift the number one placement to the right to add the newest integer.
|
||||
sub $48, %dx
|
||||
jmp convertdone # In ascii, numbers start at 0 = 48, 1 = 49, 2 = 50 and so on. So I subtract 48 to get the digit.
|
||||
|
||||
not_a_num:
|
||||
xor %dx, %dx
|
||||
|
||||
convertdone:
|
||||
|
||||
pop %cx
|
||||
pop %bx
|
||||
|
||||
mov %bp, %sp
|
||||
pop %bp
|
||||
ret
|
||||
|
||||
|
||||
_boot:
|
||||
mWriteString welcome
|
||||
|
||||
guess:
|
||||
call get_number
|
||||
xor %ah, %ah
|
||||
call string_to_int
|
||||
|
||||
cmp $5, %dx
|
||||
|
||||
jl if_lower
|
||||
je if_eg
|
||||
jg if_higher
|
||||
|
||||
if_lower:
|
||||
mWriteString lower_msg
|
||||
jmp guess
|
||||
|
||||
if_higher:
|
||||
mWriteString higher_msg
|
||||
jmp guess
|
||||
|
||||
if_eg:
|
||||
mWriteString winner_msg
|
||||
|
||||
#move to 510th byte from the start and append boot signature
|
||||
. = _start + 510
|
||||
.byte 0x55
|
||||
.byte 0xaa
|
||||
@@ -0,0 +1,135 @@
|
||||
#generate 16-bit code
|
||||
.code16
|
||||
|
||||
#hint the assembler that here is the executable code located
|
||||
.text
|
||||
.globl _start;
|
||||
#boot code entry
|
||||
_start:
|
||||
welcome: .asciz "Welcome to this very fine Guessing game \n\r" #here we define the string
|
||||
enter_number: .asciz "Enter a number: \n"
|
||||
lower_msg: .asciz "Your number is to low :( \n" # 26
|
||||
higher_msg: .asciz "Your number is to high :( \n" # 27
|
||||
winner_msg: .asciz "Your are the CAMPION, :D \n" # 26
|
||||
.macro mWriteString str #macro which calls a function to print a string
|
||||
leaw \str, %si
|
||||
call .writeStringIn
|
||||
.endm
|
||||
#jmp _boot
|
||||
|
||||
# function to print the string
|
||||
.writeStringIn:
|
||||
lodsb
|
||||
orb %al, %al
|
||||
jz .writeStringOut
|
||||
movb $0x0e, %ah
|
||||
int $0x10
|
||||
jmp .writeStringIn
|
||||
.writeStringOut:
|
||||
ret #jump to boot code
|
||||
|
||||
mWriteString welcome
|
||||
|
||||
/*
|
||||
guess:
|
||||
call get_number
|
||||
xor %ah, %ah
|
||||
call string_to_int
|
||||
|
||||
cmp $5, %dx
|
||||
|
||||
jl if_lower # rax less then 50
|
||||
je if_eg
|
||||
jg if_higher
|
||||
if_lower:
|
||||
mWriteString lower_msg
|
||||
jmp guess
|
||||
|
||||
if_higher:
|
||||
mWriteString higher_msg
|
||||
jmp guess
|
||||
|
||||
if_eg:
|
||||
mWriteString winner_msg #message length
|
||||
|
||||
hlt
|
||||
*/
|
||||
#_boot:
|
||||
# mWriteString welcome
|
||||
|
||||
|
||||
|
||||
#.type string_to_int, @function
|
||||
#string_to_int:
|
||||
/* Converts a string to an integer. Returns the integer in %rax.
|
||||
* %rax: Address of string to convert.
|
||||
*/
|
||||
/*
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
push %bx
|
||||
push %cx
|
||||
|
||||
mov %ax, %dx
|
||||
|
||||
xor %ax, %ax
|
||||
|
||||
cmp $47, %dx
|
||||
jl not_a_num
|
||||
cmp $57, %dx
|
||||
jg not_a_num
|
||||
# I multiply by 10 to shift the number one placement to the right to add the newest integer.
|
||||
sub $48, %dx # In ascii, numbers start at 0 = 48, 1 = 49, 2 = 50 and so on. So I subtract 48 to get the digit.
|
||||
|
||||
not_a_num:
|
||||
xor %dx, %dx
|
||||
|
||||
convertdone:
|
||||
|
||||
pop %cx
|
||||
pop %bx
|
||||
|
||||
mov %bp, %sp
|
||||
pop %bp
|
||||
ret
|
||||
|
||||
.type get_number, @function
|
||||
get_number:
|
||||
# .enter_char:
|
||||
# mov $0, %ah
|
||||
# mov $0, %al
|
||||
# int $0x16
|
||||
|
||||
# mov $0x0E, %ah
|
||||
# int $0x10
|
||||
|
||||
# jmp .enter_char
|
||||
|
||||
# save state before function
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
push %bx
|
||||
push %cx
|
||||
# Start of function
|
||||
mWriteString enter_number
|
||||
|
||||
mov $0, %ah
|
||||
mov $0, %al
|
||||
int $0x16
|
||||
|
||||
mov $0x0E, %ah
|
||||
int $0x10
|
||||
|
||||
pop %cx
|
||||
pop %bx
|
||||
|
||||
mov %bp, %sp
|
||||
pop %bp
|
||||
ret
|
||||
*/
|
||||
#move to 510th byte from the start and append boot signature
|
||||
. = _start + 510
|
||||
.byte 0x55
|
||||
.byte 0xaa
|
||||
Reference in new issue
Block a user