Compare commits
4 commits
43a0d9017c
...
b8a175b78f
| Author | SHA1 | Date | |
|---|---|---|---|
| b8a175b78f | |||
| cdfef627fa | |||
| 093969301e | |||
| be2d14de91 |
1 changed files with 247 additions and 25 deletions
270
lboot.S
270
lboot.S
|
|
@ -22,6 +22,7 @@
|
||||||
.code16
|
.code16
|
||||||
|
|
||||||
.set PACKET_SIZE, 512
|
.set PACKET_SIZE, 512
|
||||||
|
.set TX_BUF_SIZE, 4096
|
||||||
|
|
||||||
.macro pxe_call, opcode
|
.macro pxe_call, opcode
|
||||||
push %eax
|
push %eax
|
||||||
|
|
@ -38,7 +39,8 @@
|
||||||
lcall *pxe_api
|
lcall *pxe_api
|
||||||
add $6, %sp
|
add $6, %sp
|
||||||
|
|
||||||
or %ss:(%bx), %ax
|
mov %ss:(%bx), %cx
|
||||||
|
or %cx, %ax
|
||||||
jnz _pcerr
|
jnz _pcerr
|
||||||
|
|
||||||
pop %edx
|
pop %edx
|
||||||
|
|
@ -57,6 +59,8 @@ _start: cli
|
||||||
|
|
||||||
call init_com1
|
call init_com1
|
||||||
|
|
||||||
|
mov $msg_start, %si
|
||||||
|
call print
|
||||||
mov $msg_start, %si
|
mov $msg_start, %si
|
||||||
call print
|
call print
|
||||||
|
|
||||||
|
|
@ -76,6 +80,20 @@ _start: cli
|
||||||
call print
|
call print
|
||||||
call enable_a20
|
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
|
mov $msg_unreal, %si
|
||||||
call print
|
call print
|
||||||
call unreal
|
call unreal
|
||||||
|
|
@ -92,26 +110,19 @@ _start: cli
|
||||||
call print
|
call print
|
||||||
call paging
|
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
|
mov $msg_read, %si
|
||||||
call print
|
call print
|
||||||
mov $fn_initrd, %esi
|
mov $fn_initrd, %esi
|
||||||
call read_file
|
call read_file
|
||||||
mov %ebx, bb_ird_ptr
|
mov %ebx, bb_ird_ptr
|
||||||
|
|
||||||
|
mov $msg_vbe, %si
|
||||||
|
call print
|
||||||
|
call vbe_setup
|
||||||
|
|
||||||
mov $msg_long, %si
|
mov $msg_long, %si
|
||||||
call print
|
call print
|
||||||
|
jmp hang // REMOVE ME
|
||||||
call long
|
call long
|
||||||
|
|
||||||
jmp hang
|
jmp hang
|
||||||
|
|
@ -321,6 +332,11 @@ tftp_open: push %ecx
|
||||||
push %bp
|
push %bp
|
||||||
mov %sp, %bp
|
mov %sp, %bp
|
||||||
|
|
||||||
|
mov %esi, %ebx
|
||||||
|
|
||||||
|
mov $msg_topen, %si
|
||||||
|
call print
|
||||||
|
|
||||||
push $PACKET_SIZE
|
push $PACKET_SIZE
|
||||||
push $69<<8
|
push $69<<8
|
||||||
mov $128, %ecx
|
mov $128, %ecx
|
||||||
|
|
@ -328,12 +344,28 @@ tftp_open: push %ecx
|
||||||
mov %ss, %edi
|
mov %ss, %edi
|
||||||
shl $4, %edi
|
shl $4, %edi
|
||||||
add %esp, %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
|
addr32 rep movsb
|
||||||
push $0
|
push gateway_ip+2
|
||||||
push $0
|
push gateway_ip
|
||||||
push server_ip+2
|
push server_ip+2
|
||||||
push server_ip
|
push server_ip
|
||||||
push $0
|
push $0
|
||||||
|
|
||||||
|
mov %ss, %esi
|
||||||
|
shl $4, %esi
|
||||||
|
add %esp, %esi
|
||||||
|
mov $128, %ecx
|
||||||
|
call dump
|
||||||
|
|
||||||
pxe_call PXE_TFTP_OPEN
|
pxe_call PXE_TFTP_OPEN
|
||||||
|
|
||||||
leave
|
leave
|
||||||
|
|
@ -346,6 +378,9 @@ tftp_open: push %ecx
|
||||||
tftp_close: push %bp
|
tftp_close: push %bp
|
||||||
mov %sp, %bp
|
mov %sp, %bp
|
||||||
|
|
||||||
|
mov $msg_tclose, %si
|
||||||
|
call print
|
||||||
|
|
||||||
push $0
|
push $0
|
||||||
pxe_call PXE_TFTP_CLOSE
|
pxe_call PXE_TFTP_CLOSE
|
||||||
|
|
||||||
|
|
@ -357,6 +392,9 @@ tftp_read: push %ebx
|
||||||
push %bp
|
push %bp
|
||||||
mov %sp, %bp
|
mov %sp, %bp
|
||||||
|
|
||||||
|
mov $msg_tread, %si
|
||||||
|
call print
|
||||||
|
|
||||||
push %cs
|
push %cs
|
||||||
push $tx_buf
|
push $tx_buf
|
||||||
push $0
|
push $0
|
||||||
|
|
@ -375,25 +413,201 @@ out_of_mem: mov $msg_memerr, %si
|
||||||
jmp hang
|
jmp hang
|
||||||
|
|
||||||
// print: print NUL-terminated string pointed to by SI
|
// print: print NUL-terminated string pointed to by SI
|
||||||
print: xor %bx, %bx
|
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
|
||||||
|
|
||||||
_prnext: mov $COM1+5, %dx
|
printch: push %eax
|
||||||
|
push %ebx
|
||||||
|
push %edx
|
||||||
|
push %ebp
|
||||||
|
|
||||||
|
mov %ax, %bx
|
||||||
|
|
||||||
|
1: mov $COM1+5, %dx
|
||||||
inb %dx, %al
|
inb %dx, %al
|
||||||
test $0x20, %al
|
test $0x20, %al
|
||||||
jz _prnext
|
jz 1b
|
||||||
|
|
||||||
lodsb
|
mov %bx, %ax
|
||||||
or %al, %al
|
|
||||||
jz _prdone
|
|
||||||
|
|
||||||
mov $COM1, %dx
|
mov $COM1, %dx
|
||||||
outb %al, %dx
|
outb %al, %dx
|
||||||
|
|
||||||
|
xor %bx, %bx
|
||||||
mov $0x0E, %ah
|
mov $0x0E, %ah
|
||||||
int $0x10
|
int $0x10
|
||||||
jmp _prnext
|
|
||||||
|
|
||||||
_prdone: ret
|
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
|
||||||
|
|
||||||
// long: Enter long mode
|
// long: Enter long mode
|
||||||
long:
|
long:
|
||||||
|
|
@ -491,15 +705,21 @@ msg_getmap: .asciz " * Memory Map\r\n"
|
||||||
msg_mkheap: .asciz " * Making Space\r\n"
|
msg_mkheap: .asciz " * Making Space\r\n"
|
||||||
msg_paging: .asciz " * Paging\r\n"
|
msg_paging: .asciz " * Paging\r\n"
|
||||||
msg_read: .asciz " * Retrieving\r\n"
|
msg_read: .asciz " * Retrieving\r\n"
|
||||||
|
msg_vbe: .asciz " * Framebuffer\r\n"
|
||||||
msg_long: .asciz " * Long Mode\r\n"
|
msg_long: .asciz " * Long Mode\r\n"
|
||||||
msg_pserr: .asciz "panic: Missing !PXE structure.\r\n"
|
msg_pserr: .asciz "panic: Missing !PXE structure.\r\n"
|
||||||
msg_pcerr: .asciz "panic: PXE call failed.\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_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"
|
fn_initrd: .asciz "initrd"
|
||||||
|
|
||||||
pxe_api: .long 0
|
pxe_api: .long 0
|
||||||
server_ip: .space 4
|
server_ip: .space 4
|
||||||
|
gateway_ip: .space 4
|
||||||
|
|
||||||
heap_ptr: .long 0
|
heap_ptr: .long 0
|
||||||
heap_end: .long 0
|
heap_end: .long 0
|
||||||
|
|
@ -513,7 +733,7 @@ pml4_ptr: .long 0
|
||||||
// Points to the end of the memory map
|
// Points to the end of the memory map
|
||||||
memmap_end: .short 0
|
memmap_end: .short 0
|
||||||
|
|
||||||
tx_buf: .space PACKET_SIZE
|
tx_buf: .space TX_BUF_SIZE
|
||||||
|
|
||||||
.code64
|
.code64
|
||||||
// trampo64: Trampoline function to load long-mode segments
|
// trampo64: Trampoline function to load long-mode segments
|
||||||
|
|
@ -579,6 +799,8 @@ type_table: .byte 0
|
||||||
// - Sanitizing the memmap
|
// - Sanitizing the memmap
|
||||||
// - Parsing a config file
|
// - Parsing a config file
|
||||||
|
|
||||||
|
hex_digits: .ascii "0123456789ABCDEF"
|
||||||
|
|
||||||
.section .data.bootboot
|
.section .data.bootboot
|
||||||
bootboot: .ascii "BOOT"
|
bootboot: .ascii "BOOT"
|
||||||
bb_size: .long 128
|
bb_size: .long 128
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue