Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .code16
- .global init # makes our label "init" available to the outside
- .global msg
- .global boot_disk
- .global disk_read
- .text
- #.org 0x7c00
- .equ PROGRAM_SPACE, 0x7e00
- #oṃ bhūr bhuvaḥ svaḥ
- #tat savitur vareṇyaṃ
- #bhargo devasya dhīmahi
- #dhiyo yo naḥ pracodayāt
- init:
- mov %dl, (boot_disk) #at boot the disk number is stored in %dl, store it in c har boot_disk for use in disk_read()
- .byte 0xcc #hardware interrupt
- hlt
- mov $msg, %bx
- call print
- call disk_read
- mov $msg, %bx
- call print
- infiloop_real_mode:
- jmp infiloop_real_mode
- jmp enter_protected_mode
- end_loop:
- jmp end_loop
- disk_read:
- mov $0x02, %ah
- mov $PROGRAM_SPACE, %bx
- mov $0x04, %al
- mov (boot_disk), %dl
- mov $0x00, %ch
- mov $0x00, %dh
- mov $0x02, %cl
- int $0x13 #carry flag set on fail
- jc disk_read_fail
- mov $disk_read_success_msg, %bx
- call print
- ret
- disk_read_fail:
- mov $disk_read_fail_msg, %bx
- call print
- ret
- print: # weirdest phenomena in asm history, made a function run 100% sucessfull y on first assemble
- mov $0x0e, %ah
- print_loop:
- mov (%bx), %al # sets AL to the first byte of our message
- cmp $0x00, %al je exit_print
- int $0x10 # call the function in ah from interrupt 0x10
- inc %bx
- jmp print_loop
- exit_print:
- ret
- enter_protected_mode:
- #mov $msg, %bx
- call enable_A20
- mov $msg, %bx
- #call sleep
- #call sleep
- mov $msg,%bx
- call print
- #call sleep
- mov $msg, %bx
- call sleep
- #jmp enter_protected_mode
- cli #cli clear interupt, interrupts need to be disabled to e nter protected mode
- lgdt (gdt_descriptor) #load global table desctiptor
- mov %cr0, %eax
- or $0x01, %eax
- mov %eax, %cr0
- mov $sector_2_msg, %bx
- call print
- hlt
- # problemer
- jmp $0x7e00, $0x0
- enable_A20:
- in $0x92, %al
- or %al, 0x02
- out %al, $0x92
- ret
- sleep:
- mov $0xffff, %ax
- xor %bx, %bx #bx = 0x00000
- sleep_loop:
- dec %ax
- cmp %ax, %bx
- jne sleep_loop
- ret
- ## Data ------------------------------------
- msg:
- .asciz "not not\r\n"
- disk_read_fail_msg:
- .asciz "fail Disk read\r\n"
- disk_read_success_msg:
- .asciz "sucess Disk read\r\n"
- boot_disk:
- .byte 0x00
- #.org 0x7e00
- #sector 2 data
- sector_2_msg:
- .asciz "Running in sector 2\r\n"
- ##global descriptor table (gdt)
- gdt_nulldesc:
- .byte 0x00
- .byte 0x00
- gdt_codedesc:
- .word 0xffff #limit
- .word 0x0000 #base (low 16 bit)
- .byte 0x00 #base (medium 8 bits)
- .byte 0b10011010 #flags(binary)
- .byte 0b11001111 #flags(4 bits) limit(4 bits)
- .byte 0x00 #base (high 8 bits)
- gdt_datadesc:
- .word 0xffff #limit
- .word 0x0000 #base (low 16 bit)
- .byte 0x00 #base (medium 8 bits)
- .byte 0b10010010 #flags(binary)
- .byte 0b11001111 #flags(4 bits) limit(4 bits)
- .byte 0x00 #base (high 8 bits)
- gdt_end:
- gdt_descriptor:
- .word gdt_end - gdt_nulldesc -1
- .long gdt_nulldesc
- .equ CODESEG, gdt_codedesc - gdt_nulldesc
- .equ DATASEG, gdt_datadesc - gdt_nulldesc
- ##ROGRAM_SPACE refers to this portion of memory
- # mov $sector_2_msg, %bx
- # call print
- # nop
- # nop
- # nop
- # nop
- ## 32 bit protected mode setup
- .fill 510-(.-init), 1, 0 # add zeroes to make it 510 bytes long
- .word 0xaa55
- #etter her så blir det 513 til 2048
- .code32
- sector_2:
- protected_mode_32:
- loopinz:
- jmp loopinz
- .byte 0xcc
- movl $DATASEG, %eax
- movl %eax, %ds
- movl %eax, %gs
- movl %eax, %ss
- movl %eax, %fs
- movl %eax, %es
- xorl %eax, %eax
- #movl %eax, %cs
- sti
- movl $0x07690748,0xb8000
- # movb $0x41, (0x000b8000)
- # movb $0X2A, (0X000B8000)
- infloop:
- jmp infloop
- .fill 2048-(.-protected_mode_32), 1, 0 # zero pad sector 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement