| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /* arch/x86/boot/boot32.S
- *
- * This file is part of evx.
- *
- * evx is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * evx is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with evx. If not, see <https://www.gnu.org/licenses/>
- */
- .code16
- /* load system to 0x8000, and boot */
- .globl _start
- _start: xorw %ax, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
- movw $0x7c00, %sp
- /* move self to 0x7e00 */
- movw $0x7e00, %di
- movw $0x7c00, %si
- movw $512, %cx
- cld
- rep
- movsb
- ljmp $0x0000, $real_start
- real_start:
- leaw loading_msg, %si
- call print
- call load_sys
- call setup_e820
- ljmp $0, $0x8000
- die: hlt
- jmp die
- load_sys:
- /* load the system to 0x8000, and jump */
- movw $0x0800, %ax
- movw %ax, %es
- xorw %bx, %bx
- movl $1, %eax
- lloop: movw $16, %cx
- call read_lba
- movw %es, %cx
- addw $512, %cx
- movw %cx, %es
- addl $16, %eax
- cmpl $64, %eax
- jb cont
- ret
- cont: pushal
- /* put a '.' on screen */
- movb $'.', %al
- movb $0x0e, %ah
- movw $0x000f, %bx
- int $0x10
- popal
- jmp lloop
- read_lba:
- pushaw
- pushl $0
- pushl %eax
- pushw %es
- pushw %bx
- pushw %cx
- pushw $16
- movb $0x42, %ah
- /* dx didn't change */
- movw %sp, %si
- int $0x13
- jc read_failed
- addw $16, %sp
- popaw
- ret
- read_failed:
- leaw read_fail_msg, %si
- call print
- jmp die
- setup_e820:
- movl $0x9000, %ebx
- movl %ebx, %es
- xorl %edi, %edi
- xorl %ebx, %ebx
- sel: movl $0xe820, %eax
- movl $20, %ecx
- movl $0x534d4150, %edx
- int $0x15
- jc e820_failed
- addl $20, %edi
- cmpl $0, %ebx
- jne sel
- ret
- e820_failed:
- leaw e820_fail_msg, %si
- pushw $die
- print: cld
- lodsb
-
- testb %al, %al
- jz pret
- movb $0x0e, %ah
- movw $0x000f, %bx
- int $0x10
- jmp print
- pret: ret
- read_fail_msg:
- .ascii "read /dev/sda failed. "
- .byte 0x0d, 0x0a, 0x00
- loading_msg:
- .asciz "Loading System"
- e820_fail_msg:
- .asciz "get e820 meminfo failed. "
- .org 0x1be
- part0:
- .org 510
- .word 0xaa55
|