From 94919ad0c77d93c16e16532e266bd5794d795abf Mon Sep 17 00:00:00 2001 From: Thomas Oltmann Date: Mon, 7 Jul 2025 02:10:02 +0200 Subject: [PATCH] Opening a TFTP file stream --- fernlader.cfg | 1 + lboot.S | 101 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 fernlader.cfg diff --git a/fernlader.cfg b/fernlader.cfg new file mode 100644 index 0000000..b44de3e --- /dev/null +++ b/fernlader.cfg @@ -0,0 +1 @@ +kernel=sys/core diff --git a/lboot.S b/lboot.S index 8897e10..0c2240c 100644 --- a/lboot.S +++ b/lboot.S @@ -4,9 +4,22 @@ .text .code16 + .macro pxe_call, opcode + mov %sp, %bx + push %ss + push %bx + push $\opcode + lcall *pxe_api + add $6, %sp + mov %sp, %bx + or %ss:(%bx), %ax + jnz _pcerr + .endm + // _start: entry point _start: cli cld + mov %sp, %bp // we keep our text and data close to each other xor %ax, %ax @@ -17,6 +30,18 @@ _start: cli mov $msg_start, %si call print + mov %ss:4(%bp), %si + mov %ss:6(%bp), %ax + mov %ax, %es + .set PXE_MAGIC, 0x45585021 + cmpl $PXE_MAGIC, %es:(%si) + je 1f + mov $msg_pserr, %si + call print + jmp hang +1: mov %es:16(%si), %eax + mov %eax, pxe_api + mov $msg_a20, %si call print call enable_a20 @@ -37,6 +62,22 @@ _start: cli call print call paging + .set PXE_GET_CACHED_INFO, 0x0071 + push $0 + push %cs + push $tx_buf + push $1024 + 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 + call read_file + mov $msg_long, %si call print call long @@ -44,11 +85,11 @@ _start: cli jmp hang .set COM1, 0x3F8 -.macro com1_write offset=0, byte + .macro com1_write offset=0, byte mov $COM1+\offset, %dx mov $\byte, %al outb %al, %dx -.endm + .endm // init_com1: Set up COM1 port for debug output init_com1: com1_write 1, 0x00 // clear interrupts @@ -211,6 +252,39 @@ _aerr: mov $msg_aerr, %si call print jmp hang +read_file: + .set PXE_TFTP_OPEN, 0x0020 + push $1024 + push $0x4500 + sub $128, %sp + + mov $fn_config, %esi + mov %ss, %ax + mov %ax, %es + mov %esp, %edi + mov $fn_config_l, %ecx + rep movsb + + push $0 + push $0 + + sub $4, %sp + mov %sp, %di + mov server_ip+0, %al + mov %al, %ss:0(%di) + mov server_ip+1, %al + mov %al, %ss:1(%di) + mov server_ip+2, %al + mov %al, %ss:2(%di) + mov server_ip+3, %al + mov %al, %ss:3(%di) + + push $0 + pxe_call PXE_TFTP_OPEN + add $14+128, %sp + + ret + // print: print NUL-terminated string pointed to by SI print: xor %bx, %bx @@ -269,6 +343,10 @@ long: hang: hlt jmp hang +_pcerr: mov $msg_pcerr, %si + call print + jmp hang + // gdt16: Protected mode / Unreal mode 16-bit GDT gdt16: // entry 0: null descriptor .word 0 @@ -323,9 +401,18 @@ msg_unreal: .asciz " * Unreal Mode\r\n" 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_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_aerr: .asciz "panic: Out of heap space.\r\n" +fn_config: .asciz "fernlader.cfg" + .set fn_config_l, .-fn_config + +pxe_api: .long 0 +server_ip: .space 4 + heap_start: .long 0 heap_size: .long 0 @@ -337,6 +424,8 @@ pml4_ptr: .long 0 // Points to the end of the memory map memmap_end: .word 0 +tx_buf: .space 1024 + .code64 // trampo64: Trampoline function to load long-mode segments // before entering the loader. @@ -346,5 +435,11 @@ trampo64: mov %eax, %es mov %eax, %fs mov %eax, %gs - mov %eax, %ss // FIXME why does this crash? + mov %eax, %ss jmp loader_main + + // ToDo List: + // - Sorting the memmap + // - Sanitizing the memmap + // - Translating the memmap to bootboot format + // - Parsing a config file