TFTP_READ_FILE more or less works now

This commit is contained in:
Thomas Oltmann 2026-06-24 22:11:43 +02:00
parent 5631354405
commit 00c8672f78
2 changed files with 97 additions and 6 deletions

View file

@ -103,9 +103,9 @@ display_string(uint16_t attr, const char *str)
} }
void void
debug_write_uint(unsigned v) debug_write_uint(uint32_t v)
{ {
char buf[20], *p = buf + sizeof buf; char buf[50], *p = buf + sizeof buf;
p--; p--;
*p = 0; *p = 0;
do { do {
@ -116,6 +116,20 @@ debug_write_uint(unsigned v)
debug_write(p); debug_write(p);
} }
void
debug_write_hex(uint64_t v)
{
char buf[50], *p = buf + sizeof buf;
p--;
*p = 0;
do {
p--;
*p = "0123456789ABCDEF"[v % 16];
v /= 16;
} while (v);
debug_write(p);
}
#define PG_PRESENT 0x001 #define PG_PRESENT 0x001
#define PG_WRITE 0x002 #define PG_WRITE 0x002
#define PG_USER 0x004 #define PG_USER 0x004
@ -189,6 +203,7 @@ extern struct exPXE *exPXE;
#define PXENV_TFTP_OPEN 0x0020 #define PXENV_TFTP_OPEN 0x0020
#define PXENV_TFTP_CLOSE 0x0021 #define PXENV_TFTP_CLOSE 0x0021
#define PXENV_TFTP_READ 0x0022 #define PXENV_TFTP_READ 0x0022
#define PXENV_TFTP_READ_FILE 0x0023
typedef struct __attribute__((packed)) s_PXENV_GET_CACHED { typedef struct __attribute__((packed)) s_PXENV_GET_CACHED {
uint16_t status; uint16_t status;
@ -220,6 +235,20 @@ typedef struct __attribute__((packed)) s_PXENV_TFTP_CLOSE {
uint16_t status; uint16_t status;
} t_PXENV_TFTP_CLOSE; } t_PXENV_TFTP_CLOSE;
typedef struct __attribute__((packed)) s_PXENV_TFTP_READ_FILE {
uint16_t status;
uint8_t filename[128];
uint32_t buffer_size;
uint32_t buffer_addr;
uint32_t server_ip;
uint32_t gateway_ip;
uint32_t mcast_ip;
uint16_t client_port;
uint16_t server_port;
uint16_t open_timeout;
uint16_t reopen_delay;
} t_PXENV_TFTP_READ_FILE;
/** /**
* return type for fs drivers * return type for fs drivers
*/ */
@ -305,6 +334,34 @@ get_cached()
debug_write("\r\n"); debug_write("\r\n");
} }
void
receive_file()
{
unsigned ret;
for (int i = 0; i < 512; i++) {
pxe_cmd_buf[i] = 0;
}
t_PXENV_TFTP_READ_FILE *t_readf = (void *)pxe_cmd_buf;
t_readf->server_ip = pxe_sip;
t_readf->gateway_ip = pxe_gip;
t_readf->buffer_addr = 0x100000;
t_readf->buffer_size = 0x100000;
memcpy(t_readf->filename, "/initrd", 8);
t_readf->server_port = 69 << 8;
debug_write("Performing TFTP_READ_FILE\r\n");
ret = pxe_call(PXENV_TFTP_READ_FILE, (uint16_t)(uintptr_t)pxe_cmd_buf, 0x0000);
debug_write("ret=");
debug_write_uint(ret);
debug_write(" status=");
debug_write_uint(t_readf->status);
debug_write("\r\n");
}
#if 0
void void
receive_file(void) receive_file(void)
{ {
@ -370,6 +427,7 @@ receive_file(void)
debug_write_uint(t_open->status); debug_write_uint(t_open->status);
debug_write("\r\n"); debug_write("\r\n");
} }
#endif
void void
main() main()
@ -392,21 +450,26 @@ main()
pxe_entry = exPXE->rmentry; pxe_entry = exPXE->rmentry;
} }
/*
memcpy(bootboot.magic, BOOTBOOT_MAGIC, sizeof bootboot.magic); memcpy(bootboot.magic, BOOTBOOT_MAGIC, sizeof bootboot.magic);
bootboot.size = 128; bootboot.size = 128;
bootboot.protocol = PROTOCOL_MINIMAL | LOADER_BIOS; bootboot.protocol = PROTOCOL_MINIMAL | LOADER_BIOS;
bootboot.numcores = 1; bootboot.numcores = 1;
debug_write("BEGIN MEMMAP\r\n");
struct e820_entry *end = bios_getmap(memmap); struct e820_entry *end = bios_getmap(memmap);
for (int i = 0; ; i++) { for (int i = 0; ; i++) {
if (&memmap[i] >= end) break; if (&memmap[i] >= end) break;
char buf[2]; char buf[3];
buf[0] = memmap[i].type < 10 ? memmap[i].type + '0' : '?'; buf[0] = memmap[i].type < 10 ? memmap[i].type + '0' : '?';
buf[1] = 0; buf[1] = ' ';
buf[2] = 0;
debug_write(buf); debug_write(buf);
debug_write_hex(memmap[i].base);
debug_write(" ");
debug_write_uint(memmap[i].length);
debug_write("\r\n");
} }
*/ debug_write("END MEMMAP\r\n");
//pg_setup(); //pg_setup();

View file

@ -52,6 +52,9 @@ _start: cli
xor %ax, %ax xor %ax, %ax
mov %ax, %es mov %ax, %es
mov $isr_double_fault, 0x0020
mov $0, 0x0020+2
// a20_enable: Allow use of 'high' (>1Mb) memory // a20_enable: Allow use of 'high' (>1Mb) memory
a20_enable: // Of all the ways to toggle A20, we only try the Fast A20 Gate. a20_enable: // Of all the ways to toggle A20, we only try the Fast A20 Gate.
@ -72,6 +75,31 @@ prot_enter: lgdt GDT_PTR
.code32 .code32
jmp main jmp main
.text
.code16
isr_double_fault:
mov $msg_double_fault, %edx
.bwloop: cmpb $0, (%edx)
jz .bwreturn
xor %bx, %bx
mov $0x0E, %ah
mov (%edx), %al
push %edx
int $0x10
pop %edx
add $1, %edx
jmp .bwloop
.bwreturn:
1: jmp 1b
msg_double_fault: .asciz "double fault"
.data .data
.global PXENV .global PXENV