| 1 | #include <lib/print.h> |
| 2 | #include <pxe/pxe.h> |
| 3 | #include <lib/libc.h> |
| 4 | #include <lib/misc.h> |
| 5 | #include <mm/pmm.h> |
| 6 | #if defined (BIOS) |
| 7 | #include <lib/real.h> |
| 8 | #elif defined (UEFI) |
| 9 | #include <efi.h> |
| 10 | #endif |
| 11 | |
| 12 | #if defined (BIOS) |
| 13 | |
| 14 | void set_pxe_fp(uint32_t fp); |
| 15 | |
| 16 | struct volume *pxe_bind_volume(void) { |
| 17 | struct volume *volume = ext_mem_alloc(sizeof(struct volume)); |
| 18 | |
| 19 | volume->pxe = true; |
| 20 | |
| 21 | return volume; |
| 22 | } |
| 23 | |
| 24 | void pxe_init(void) { |
| 25 | //pxe installation check |
| 26 | struct rm_regs r = { 0 }; |
| 27 | r.ebx = 0; |
| 28 | r.ecx = 0; |
| 29 | r.eax = 0x5650; |
| 30 | r.es = 0; |
| 31 | |
| 32 | rm_int(0x1a, &r, &r); |
| 33 | if ((r.eax & 0xffff) != 0x564e) { |
| 34 | panic(false, "PXE installation check failed"); |
| 35 | } |
| 36 | |
| 37 | struct pxenv* pxenv = { 0 }; |
| 38 | |
| 39 | pxenv = (struct pxenv*)((r.es << 4) + (r.ebx & 0xffff)); |
| 40 | if (memcmp(pxenv->signature, PXE_SIGNATURE, sizeof(pxenv->signature)) != 0) { |
| 41 | panic(false, "PXENV structure signature corrupted"); |
| 42 | } |
| 43 | |
| 44 | if (pxenv->version < 0x201) { |
| 45 | //we won't support pxe < 2.1, grub does this too and it seems to work fine |
| 46 | panic(false, "pxe version too old"); |
| 47 | } |
| 48 | |
| 49 | struct bangpxe* bangpxe = (struct bangpxe*)((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4) + (pxenv->pxe_ptr & 0xffff)); |
| 50 | |
| 51 | if (memcmp(bangpxe->signature, PXE_BANGPXE_SIGNATURE, |
| 52 | sizeof(bangpxe->signature)) |
| 53 | != 0) { |
| 54 | panic(false, "!pxe signature corrupted"); |
| 55 | } |
| 56 | set_pxe_fp(bangpxe->rm_entry); |
| 57 | printv("pxe: Successfully initialized\n"); |
| 58 | } |
| 59 | |
| 60 | #elif defined (UEFI) |
| 61 | |
| 62 | struct volume *pxe_bind_volume(EFI_HANDLE efi_handle, EFI_PXE_BASE_CODE *pxe_base_code) { |
| 63 | struct volume *volume = ext_mem_alloc(sizeof(struct volume)); |
| 64 | |
| 65 | volume->efi_handle = efi_handle; |
| 66 | volume->pxe_base_code = pxe_base_code; |
| 67 | volume->pxe = true; |
| 68 | |
| 69 | return volume; |
| 70 | } |
| 71 | |
| 72 | #endif |