assembly - Copy and execute -
i'm writing simple bootloader custom kernel. has simple logic:
- bootloader loaded bios.
- copy 0x8000.
- load kernel disk 0x9000.
- jump 0x8000 , copy kernel 0x0 , set gdt.
- jump 0x0.
here bootloader:
.set dest, 0x8000 start: movw $0x3, %ax int $0x10 movw msg, %bp movw $0xa, %cx call print_msg //copy end of bootloader new place selfcopy: cld xor %ax, %ax movw %ax, %ds movl move_kernel, %esi movw %ax, %es movl dest, %edi movl (move_kernel_end-move_kernel), %ecx rep movsb //load kernel 0x9000 load_kernel: xor %dx, %dx xor %ah, %ah int $0x10 jc reboot xor %ax, %ax movw %ax, %ds movb $0x42, %ah movw dap, %si int $0x13 jc reboot jmp dest dap: .byte 0x10 .byte 0x0 .word 2048 //offset .word 9000 .word 0x0 .long 1 move_kernel: xor %ax, %ax movw %ax, %ds movl $0x9000, %esi movw %ax, %es movl $0x0, %edi movl (move_kernel_end-move_kernel), %ecx rep movsb lgdt gdtr jmp $0x0 move_kernel_end: print_msg: //print message movw $0x0007, %bx movw $0x1301, %ax int $0x10 ret msg: .string "booting..." error_msg: .string "error..." gdt: .quad 0x0 .byte 0x0 .byte 0b11001111 .byte 0b11111010 .byte 0x0 .word 0x0 .word 0xffff .byte 0x0 .byte 0b11001111 .byte 0b11110010 .byte 0x0 .word 0x0 .word 0xffff gdtr: .long gdt .word $23 reboot: movw error_msg, %bp movw $0x8, %cx call print_msg jmp . .fill 510-(. - start), 1, 0 .byte 0x55 .byte 0xaa
so, doesn't work) if put jmp .
before jmp dest
wouldn't go infinite loop. so, wrong bootloader?
thanks.
p.s. sorry bad english.
modified code:
.set dest, 0x8000 start: movw $0x3, %ax int $0x10 pushw msg pushw $0xa call print_msg //copy end of bootloader new place selfcopy: cld xor %ax, %ax movw %ax, %ds movl move_kernel, %esi movw %ax, %es movl dest, %edi movl (move_kernel_end-move_kernel), %ecx rep movsb //load kernel 0x9000 load_kernel: xor %dx, %dx xor %ah, %ah int $0x13 jc reboot xor %ax, %ax movw %ax, %ds movb $0x42, %ah movw dap, %si int $0x13 jc reboot jmp dest dap: .byte 0x10 .byte 0x0 .word 2048 //offset .word 9000 .word 0x0 .long 1 move_kernel: cli xor %ax, %ax movw %ax, %ds movl $0x9000, %esi movw %ax, %es movl $0x0, %edi movl (move_kernel_end-move_kernel), %ecx rep movsb lgdt gdtr jmp . sti jmp $0x0 move_kernel_end: print_msg: //print message popw %ax popw %cx popw %bp pushl %eax movb $0x07, %bl movb $0x13, %ah movb $0x1, %al int $0x10 ret msg: .string "booting..." gdt: .quad 0x0 .byte 0x0 .byte 0b11001111 .byte 0b11111010 .byte 0x0 .word 0x0 .word 0xffff .byte 0x0 .byte 0b11001111 .byte 0b11110010 .byte 0x0 .word 0x0 .word 0xffff gdtr: .long gdt .word 23 reboot: pushw $0xdead pushw $0x8 call print_msg .fill 510-(. - start), 1, 0 .byte 0x55 .byte 0xaa
Comments
Post a Comment