Re: Custom boot loader stub
Sad Clouds <[email protected]> Thu, 23 Oct 2025 11:09:55 +0100
| Newsgroups | gmane.os.netbsd.ports.sparc64 |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 17 Oct 2025 12:32:36 +0300 Valery Ushakov <[email protected]> wrote: > Yes, as I said, see how sparc boot code does that: "romp", > common/prompdev.c, and ofwboot/promlib.c - its ofw subclass. Start > here: > > https://github.com/NetBSD/src/blob/d37c7118/sys/arch/sparc/stand/common/srt0.S#L152 Well, I managed to figure out how to use Open Firmware client interface. I can print various diagnostic messages on boot: {0} ok boot /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/storage@3/disk@0 Boot device: /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/storage@3/disk@0 File and args: Running SPARC-V9 bootblk ihandle_stdin 0xFEB51F90 ihandle_stdout 0xFEB51D88 The only issue I'm having is reading from stdin always returns -2. I looked at Illumos src/psm/promif/ieee1275/common/prom_getchar.c and it is very similar to my function: int64_t ofw_read_stdin(char *strbuf, uint32_t strbuf_len) { ofw_cell_cdt ci_arg[7]; /* If stdin ihandle is not initialised, return -1 */ if (ihandle_stdin == (ihandle_cdt)-1) { return -1; } ci_arg[0] = (ofw_cell_cdt)"read"; /* Service */ ci_arg[1] = (ofw_cell_cdt)3; /* Number of arguments */ ci_arg[2] = (ofw_cell_cdt)1; /* Number of return values */ ci_arg[3] = (ofw_cell_cdt)ihandle_stdin; /* Arg1: stdin ihandle */ ci_arg[4] = (ofw_cell_cdt)strbuf; /* Arg2: strbuf address */ ci_arg[5] = (ofw_cell_cdt)strbuf_len; /* Arg3: str length */ ci_arg[6] = (ofw_cell_cdt)-1; /* Ret1: return value */ /* Call into cif handler */ ofw_cif_handler(ci_arg); return (int64_t)ci_arg[6]; } But when I try to read 1 char from stdin: i64 = ofw_read_stdin(strbuf, 1); The return value is -2 and no char is read from stdin. The hex values for stdin and stdout ihandles seem to be correct and match the ones from: {0} ok show-props /chosen Similar code works for stdout, so not sure if I'm missing something. The bootblk seems to work up to 10 KiB in size, any bigger and I get ERROR: Last Trap: Fast Data Access MMU Miss Which I guess is expected. When I have some spare time, I will try loading the 2nd stage bootloader and may be using "chain" function to execute that.