Compare commits
No commits in common. "b8a175b78fff3fa765bdbfb95f728029049d6ad4" and "43a0d9017c380bf3320ae5cb2d62a792422b0736" have entirely different histories.
b8a175b78f
...
43a0d9017c
1 changed files with 25 additions and 247 deletions
272
lboot.S
272
lboot.S
|
|
@ -22,7 +22,6 @@
|
|||
.code16
|
||||
|
||||
.set PACKET_SIZE, 512
|
||||
.set TX_BUF_SIZE, 4096
|
||||
|
||||
.macro pxe_call, opcode
|
||||
push %eax
|
||||
|
|
@ -39,8 +38,7 @@
|
|||
lcall *pxe_api
|
||||
add $6, %sp
|
||||
|
||||
mov %ss:(%bx), %cx
|
||||
or %cx, %ax
|
||||
or %ss:(%bx), %ax
|
||||
jnz _pcerr
|
||||
|
||||
pop %edx
|
||||
|
|
@ -59,8 +57,6 @@ _start: cli
|
|||
|
||||
call init_com1
|
||||
|
||||
mov $msg_start, %si
|
||||
call print
|
||||
mov $msg_start, %si
|
||||
call print
|
||||
|
||||
|
|
@ -80,20 +76,6 @@ _start: cli
|
|||
call print
|
||||
call enable_a20
|
||||
|
||||
.set PXE_GET_CACHED_INFO, 0x0071
|
||||
push $0
|
||||
push %cs
|
||||
push $tx_buf
|
||||
push $TX_BUF_SIZE
|
||||
push $2
|
||||
push $0
|
||||
pxe_call PXE_GET_CACHED_INFO
|
||||
add $12, %sp
|
||||
mov tx_buf+20, %eax
|
||||
mov %eax, server_ip
|
||||
mov tx_buf+24, %eax
|
||||
mov %eax, gateway_ip
|
||||
|
||||
mov $msg_unreal, %si
|
||||
call print
|
||||
call unreal
|
||||
|
|
@ -110,19 +92,26 @@ _start: cli
|
|||
call print
|
||||
call paging
|
||||
|
||||
.set PXE_GET_CACHED_INFO, 0x0071
|
||||
push $0
|
||||
push %cs
|
||||
push $tx_buf
|
||||
push $PACKET_SIZE
|
||||
push $2
|
||||
push $0
|
||||
pxe_call PXE_GET_CACHED_INFO
|
||||
add $12, %sp
|
||||
mov tx_buf+20, %eax
|
||||
mov %eax, server_ip
|
||||
|
||||
mov $msg_read, %si
|
||||
call print
|
||||
mov $fn_initrd, %esi
|
||||
call read_file
|
||||
mov %ebx, bb_ird_ptr
|
||||
|
||||
mov $msg_vbe, %si
|
||||
call print
|
||||
call vbe_setup
|
||||
|
||||
mov $msg_long, %si
|
||||
call print
|
||||
jmp hang // REMOVE ME
|
||||
call long
|
||||
|
||||
jmp hang
|
||||
|
|
@ -332,40 +321,19 @@ tftp_open: push %ecx
|
|||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov %esi, %ebx
|
||||
|
||||
mov $msg_topen, %si
|
||||
call print
|
||||
|
||||
push $PACKET_SIZE
|
||||
push $69<<8
|
||||
mov $128, %ecx
|
||||
sub %cx, %sp
|
||||
sub %cx, %sp
|
||||
mov %ss, %edi
|
||||
shl $4, %edi
|
||||
add %esp, %edi
|
||||
xor %ax, %ax
|
||||
cld
|
||||
addr32 rep stosb
|
||||
mov %ebx, %esi
|
||||
mov $6, %ecx
|
||||
mov %ss, %edi
|
||||
shl $4, %edi
|
||||
add %esp, %edi
|
||||
cld
|
||||
addr32 rep movsb
|
||||
push gateway_ip+2
|
||||
push gateway_ip
|
||||
push $0
|
||||
push $0
|
||||
push server_ip+2
|
||||
push server_ip
|
||||
push $0
|
||||
|
||||
mov %ss, %esi
|
||||
shl $4, %esi
|
||||
add %esp, %esi
|
||||
mov $128, %ecx
|
||||
call dump
|
||||
|
||||
pxe_call PXE_TFTP_OPEN
|
||||
|
||||
leave
|
||||
|
|
@ -378,9 +346,6 @@ tftp_open: push %ecx
|
|||
tftp_close: push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov $msg_tclose, %si
|
||||
call print
|
||||
|
||||
push $0
|
||||
pxe_call PXE_TFTP_CLOSE
|
||||
|
||||
|
|
@ -392,9 +357,6 @@ tftp_read: push %ebx
|
|||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov $msg_tread, %si
|
||||
call print
|
||||
|
||||
push %cs
|
||||
push $tx_buf
|
||||
push $0
|
||||
|
|
@ -413,201 +375,25 @@ out_of_mem: mov $msg_memerr, %si
|
|||
jmp hang
|
||||
|
||||
// print: print NUL-terminated string pointed to by SI
|
||||
print: push %eax
|
||||
push %si
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
1: lodsb
|
||||
or %al, %al
|
||||
jz 2f
|
||||
call printch
|
||||
jmp 1b
|
||||
2: leave
|
||||
pop %si
|
||||
pop %eax
|
||||
ret
|
||||
print: xor %bx, %bx
|
||||
|
||||
printch: push %eax
|
||||
push %ebx
|
||||
push %edx
|
||||
push %ebp
|
||||
|
||||
mov %ax, %bx
|
||||
|
||||
1: mov $COM1+5, %dx
|
||||
_prnext: mov $COM1+5, %dx
|
||||
inb %dx, %al
|
||||
test $0x20, %al
|
||||
jz 1b
|
||||
jz _prnext
|
||||
|
||||
mov %bx, %ax
|
||||
lodsb
|
||||
or %al, %al
|
||||
jz _prdone
|
||||
|
||||
mov $COM1, %dx
|
||||
outb %al, %dx
|
||||
|
||||
xor %bx, %bx
|
||||
mov $0x0E, %ah
|
||||
int $0x10
|
||||
jmp _prnext
|
||||
|
||||
pop %ebp
|
||||
pop %edx
|
||||
pop %ebx
|
||||
pop %eax
|
||||
ret
|
||||
|
||||
dump: push %eax
|
||||
push %ebx
|
||||
push %ecx
|
||||
push %edx
|
||||
push %esi
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
xor %dx, %dx
|
||||
|
||||
1: cmp %cx, %dx
|
||||
jae 2f
|
||||
inc %dx
|
||||
|
||||
addr32 lodsb
|
||||
push %ax
|
||||
mov %al, %bl
|
||||
shr $4, %bx
|
||||
and $0x0F, %bx
|
||||
mov hex_digits(%bx), %al
|
||||
call printch
|
||||
pop %bx
|
||||
and $0x0F, %bx
|
||||
mov hex_digits(%bx), %al
|
||||
call printch
|
||||
|
||||
mov $' ', %al
|
||||
call printch
|
||||
test $0xF, %dx
|
||||
jnz 1b
|
||||
mov $'\r', %al
|
||||
call printch
|
||||
mov $'\n', %al
|
||||
call printch
|
||||
jmp 1b
|
||||
|
||||
2: mov $'\r', %al
|
||||
call printch
|
||||
mov $'\n', %al
|
||||
call printch
|
||||
|
||||
leave
|
||||
pop %esi
|
||||
pop %edx
|
||||
pop %ecx
|
||||
pop %ebx
|
||||
pop %eax
|
||||
ret
|
||||
|
||||
vbe_setup:
|
||||
push %ecx
|
||||
push %esi
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
call vbe_getinfo
|
||||
|
||||
mov vbe_info+14, %si
|
||||
mov vbe_info+16, %cx
|
||||
mov %cx, %fs
|
||||
|
||||
_vbenext: mov %fs:(%si), %cx
|
||||
add $2, %si
|
||||
cmp $0xFFFF, %cx
|
||||
je _vbedone
|
||||
|
||||
call vbe_getmode
|
||||
|
||||
testw $0x80, tx_buf
|
||||
jz _vbenext
|
||||
|
||||
mov %cx, %bx
|
||||
and $0x0FFF, %bx
|
||||
or $0x4000, %bx
|
||||
call vbe_setmode
|
||||
|
||||
jmp _vbedone
|
||||
|
||||
_vbedone:
|
||||
leave
|
||||
pop %esi
|
||||
pop %ecx
|
||||
ret
|
||||
|
||||
vbe_getinfo:
|
||||
push %eax
|
||||
push %edi
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov $0x4F00, %ax
|
||||
mov $vbe_info, %di
|
||||
int $0x10
|
||||
|
||||
cmp $0x4F, %ax
|
||||
je 1f
|
||||
mov $msg_vbeerr, %si
|
||||
call print
|
||||
jmp hang
|
||||
1:
|
||||
|
||||
cmpl $0x41534556, vbe_info // "VESA"
|
||||
je 1f
|
||||
mov $msg_vbeerr, %si
|
||||
call print
|
||||
jmp hang
|
||||
|
||||
1: leave
|
||||
pop %edi
|
||||
pop %eax
|
||||
ret
|
||||
|
||||
vbe_getmode:
|
||||
push %eax
|
||||
push %edi
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov $0x4F01, %ax
|
||||
mov $tx_buf, %di
|
||||
int $0x10
|
||||
|
||||
cmp $0x4F, %ax
|
||||
je 1f
|
||||
mov $msg_vbeerr, %si
|
||||
call print
|
||||
jmp hang
|
||||
|
||||
1: leave
|
||||
pop %edi
|
||||
pop %eax
|
||||
ret
|
||||
|
||||
vbe_setmode:
|
||||
push %eax
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
|
||||
mov $0x4F02, %ax
|
||||
int $0x10
|
||||
|
||||
cmp $0x4F, %ax
|
||||
je 1f
|
||||
mov $msg_vbeerr, %si
|
||||
call print
|
||||
jmp hang
|
||||
|
||||
1: leave
|
||||
pop %eax
|
||||
ret
|
||||
|
||||
vbe_info:
|
||||
.ascii "VBE2"
|
||||
.skip 512 - 4
|
||||
_prdone: ret
|
||||
|
||||
// long: Enter long mode
|
||||
long:
|
||||
|
|
@ -705,21 +491,15 @@ msg_getmap: .asciz " * Memory Map\r\n"
|
|||
msg_mkheap: .asciz " * Making Space\r\n"
|
||||
msg_paging: .asciz " * Paging\r\n"
|
||||
msg_read: .asciz " * Retrieving\r\n"
|
||||
msg_vbe: .asciz " * Framebuffer\r\n"
|
||||
msg_long: .asciz " * Long Mode\r\n"
|
||||
msg_pserr: .asciz "panic: Missing !PXE structure.\r\n"
|
||||
msg_pcerr: .asciz "panic: PXE call failed.\r\n"
|
||||
msg_vbeerr: .asciz "panic: VBE call failed.\r\n"
|
||||
msg_memerr: .asciz "panic: Out of heap space.\r\n"
|
||||
msg_topen: .asciz "tftp_open\r\n"
|
||||
msg_tclose: .asciz "tftp_close\r\n"
|
||||
msg_tread: .asciz "tftp_read\r\n"
|
||||
|
||||
fn_initrd: .asciz "initrd"
|
||||
|
||||
pxe_api: .long 0
|
||||
server_ip: .space 4
|
||||
gateway_ip: .space 4
|
||||
|
||||
heap_ptr: .long 0
|
||||
heap_end: .long 0
|
||||
|
|
@ -733,7 +513,7 @@ pml4_ptr: .long 0
|
|||
// Points to the end of the memory map
|
||||
memmap_end: .short 0
|
||||
|
||||
tx_buf: .space TX_BUF_SIZE
|
||||
tx_buf: .space PACKET_SIZE
|
||||
|
||||
.code64
|
||||
// trampo64: Trampoline function to load long-mode segments
|
||||
|
|
@ -799,8 +579,6 @@ type_table: .byte 0
|
|||
// - Sanitizing the memmap
|
||||
// - Parsing a config file
|
||||
|
||||
hex_digits: .ascii "0123456789ABCDEF"
|
||||
|
||||
.section .data.bootboot
|
||||
bootboot: .ascii "BOOT"
|
||||
bb_size: .long 128
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue