Port-sparc64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Custom boot loader stub



On Fri, 17 Oct 2025 00:11:20 +0300
Valery Ushakov <uwe%stderr.spb.ru@localhost> wrote:

> [off-list]
> 
> On Thu, Oct 16, 2025 at 14:32:15 +0100, Sad Clouds wrote:
> 
> > I think OpenBoot can execute both, Forth byte codes and SPARC binaries.
> > So I'm trying to understand how to execute SPARC binaries and in what
> > format they should be.
> 
> Well, go to the source of truth :)
> 
>   https://github.com/openbios/openboot
> 
> From a quick glance at its obp/arch/sun4u/go.fth
> 
>   https://github.com/openbios/openboot/blob/1a08f436/obp/arch/sun4u/go.fth#L111
> 
> I guess it will try in order elf32, elf64, and a.out
> 
> The check for h# 107 is the a.out's OMAGIC (0407).
> 
> -uwe

Brilliant, thanks for that. I didn't realise OpenBoot was open sourced
on github. Also what is interesting in go.fth on line 75 the pointer to
client interface is passed in %o4 register, I think.

I can now execute a very minimal bootloader on Sun T5220 with ELF64
binary. The next step is to figure out how to call IEEE-1275 client
interface functions so I can print messages on the screen.

# cat boot.s
.section .text
.align 4
.global _start

_start:
        ! Uncomment to execute sir instruction.
        ! On sun4v this should result in Illegal Instruction trap
        ! as only hypervisor is allowed to execute sir.
        !sir

        ! Execute infinite loop incrementing value in %l0
        mov %g0, %l0  ! %l0 = 0
loop:
        ba loop
         inc %l0      ! %l0 += 1

# as -o boot.o boot.s && ld -o boot.bin boot.o
# file boot.bin
boot.bin: ELF 64-bit MSB executable, SPARC V9, relaxed memory ordering, version 1 (SYSV), statically linked, not stripped

# ./sparc_disk_label write /dev/sd1c
# dd if=boot.bin of=/dev/sd1c bs=512 seek=1 && sync

Fake disk label at sector 0, then boot.bin at sector 1.


Home | Main Index | Thread Index | Old Index