Initial revision

This commit is contained in:
Michael Brown
2005-03-08 18:53:11 +00:00
commit 3d6123e69a
373 changed files with 114041 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
# Config for ia64 Etherboot
#
# Do not delete the tag OptionDescription and /OptionDescription
# It is used to automatically generate the documentation.
#
# @OptionDescrition@
#
# BIOS interface options:
#
# -DCONFIG_EFI
# Compile in support for EFI
#
# @/OptionDescription@
CFLAGS+= -DCONSOLE_FIRMWARE
CFLAGS+= -DCONFIG_EFI
CFLAGS+= -fpic -mconstant-gp -mauto-pic
ASFLAGS+= -mconstant-gp -mauto-pic
LDFLAGS+= -static -shared -Bsymbolic --warn-multiple-gp --warn-common
+125
View File
@@ -0,0 +1,125 @@
ARCH_FORMAT= elf64-ia64-little
LCONFIG+=
BUILD_EFIS= $(patsubst %.img, %.efi, $(IMGS)) $(patsubst %.img, %.zefi, $(IMGS))
START= $(BIN)/start.o $(BIN)/reloc.o
#START+= $(BIN)/efi_main.o
SRCS+= arch/ia64/prefix/efi_prefix.S arch/ia64/prefix/unnrv2b.S
SRCS+= arch/ia64/core/__call.S
SRCS+= arch/ia64/core/ia64_timer.c
SRCS+= arch/ia64/core/idiv32.S
SRCS+= arch/ia64/core/idiv64.S
SRCS+= arch/ia64/core/longjmp.S
SRCS+= arch/ia64/core/memmove.S
SRCS+= arch/ia64/core/memset.S
SRCS+= arch/ia64/core/pal.c
SRCS+= arch/ia64/core/pci_io.c
SRCS+= arch/ia64/core/reloc.S
SRCS+= arch/ia64/core/relocate_to.S
SRCS+= arch/ia64/core/sal.c
SRCS+= arch/ia64/core/setjmp.S
SRCS+= arch/ia64/core/start.S
SRCS+= arch/ia64/core/efi.c
ROMLIMIT:=3276800
include $(BIN)/Roms
# We need allefis because $(IMGS) is not defined until
# the Makefile fragment "Roms" is read.
allefis: $(BUILD_EFIS)
#BOBJS+= $(BIN)/acpi.o
BOBJS+= $(BIN)/sal.o $(BIN)/pal.o
BOBJS+= $(BIN)/efi.o
BOBJS+= $(BIN)/memset.o $(BIN)/memmove.o
BOBJS+= $(BIN)/setjmp.o $(BIN)/longjmp.o
BOBJS+= $(BIN)/relocate_to.o $(BIN)/__call.o
BOBJS+= $(BIN)/pci_io.o $(BIN)/ia64_timer.o
BOBJS+= $(BIN)/__divdi3.o $(BIN)/__udivdi3.o $(BIN)/__moddi3.o $(BIN)/__umoddi3.o
BOBJS+= $(BIN)/__divsi3.o $(BIN)/__udivsi3.o $(BIN)/__modsi3.o $(BIN)/__umodsi3.o
# IA64 Division routines
$(BIN)/__divdi3.o: arch/ia64/core/idiv64.S
$(CPP) $(CFLAGS) -DASSEMBLY $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__udivdi3.o: arch/ia64/core/idiv64.S
$(CPP) $(CFLAGS) -DASSEMBLY -DUNSIGNED $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__moddi3.o: arch/ia64/core/idiv64.S
$(CPP) $(CFLAGS) -DASSEMBLY -DMODULO $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__umoddi3.o: arch/ia64/core/idiv64.S
$(CPP) $(CFLAGS) -DASSEMBLY -DUNSIGNED -DMODULO $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__divsi3.o: arch/ia64/core/idiv32.S
$(CPP) $(CFLAGS) -DASSEMBLY $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__udivsi3.o: arch/ia64/core/idiv32.S
$(CPP) $(CFLAGS) -DASSEMBLY -DUNSIGNED $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__modsi3.o: arch/ia64/core/idiv32.S
$(CPP) $(CFLAGS) -DASSEMBLY -DMODULO $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/__umodsi3.o: arch/ia64/core/idiv32.S
$(CPP) $(CFLAGS) -DASSEMBLY -DUNSIGNED -DMODULO $< | $(AS) $(ASFLAGS) -o $@
# Utilities
$(BIN)/nrv2b: util/nrv2b.c
$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG -DBITSIZE=64 -DENDIAN=0 -o $@ $<
# Pattern Rules
# General for compiling assembly source files
$(BIN)/%.o: arch/ia64/core/%.c $(MAKEDEPS)
$(CC) $(CFLAGS) -o $@ -c $<
$(BIN)/%.o: arch/ia64/prefix/%.S $(MAKEDEPS)
$(CPP) $(CFLAGS) -DASSEMBLY $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/%.o: arch/ia64/core/%.S $(MAKEDEPS)
$(CPP) $(CFLAGS) -DASSEMBLY $< | $(AS) $(ASFLAGS) -o $@
$(BIN)/%.o: $(BIN)/%.s
$(AS) $(ASFLAGS) -o $@ $<
# General rules for bootable images
# Rules for nrv2b compressed images
$(BIN)/unnrv2b.tmp: $(BIN)/unnrv2b.o arch/ia64/prefix/unnrv2b.lds $(MAKEDEPS)
$(LD) -T arch/ia64/prefix/unnrv2b.lds $< -o $@
$(BIN)/unnrv2b: $(BIN)/unnrv2b.tmp $(MAKEDEPS)
$(OBJCOPY) -O binary $< $@
$(BIN)/%.zimg: $(BIN)/%.z $(BIN)/unnrv2b arch/ia64/prefix/apply_unnrv2b_prefix.pl $(MAKEDEPS)
$(PERL) arch/ia64/prefix/apply_unnrv2b_prefix.pl $(BIN)/unnrv2b $< > $@
# Placeholder; add no extra symbols to %.sym
$(BIN)/%.zsym: $(BIN)/%.sym $(MAKEDEPS)
cp -f $< $@
# rules to generate efi loadable image
SUFFIXES += efi zefi
$(BIN)/efi_prefix.tmp: $(BIN)/efi_prefix.o arch/ia64/prefix/efi_prefix.lds $(MAKEDEPS)
$(LD) -T arch/ia64/prefix/efi_prefix.lds $< -o $@
$(BIN)/efi_prefix: $(BIN)/efi_prefix.tmp $(MAKEDEPS)
$(OBJCOPY) -O binary $< $@
$(BIN)/%.efi: $(BIN)/%.img $(BIN)/%.tmp $(BIN)/efi_prefix arch/ia64/prefix/apply_efi_prefix.pl $(MAKEDEPS)
@$(SIZE) $(BIN)/$(*).tmp | (read l1; read d1 d2 bss rest ; echo $$bss )
$(PERL) arch/ia64/prefix/apply_efi_prefix.pl $(BIN)/efi_prefix $< `$(SIZE) $(BIN)/$(*).tmp | (read l1; read d1 d2 bss rest ; echo $$bss )` > $@
$(BIN)/%.zefi: $(BIN)/%.zimg $(BIN)/%.tmp $(BIN)/efi_prefix arch/ia64/prefix/apply_efi_prefix.pl $(MAKEDEPS)
@$(SIZE) $(BIN)/$(*).tmp | (read l1; read d1 d2 d3 size rest ; echo $$size )
$(PERL) arch/ia64/prefix/apply_efi_prefix.pl $(BIN)/efi_prefix $< `$(SIZE) $(BIN)/$(*).tmp | (read l1; read d1 d2 d3 size rest ; echo $$size )` > $@
+68
View File
@@ -0,0 +1,68 @@
/* Trampoline for calling outside of etherboot */
.text
.globl __call
.proc __call
__call:
alloc loc0=ar.pfs,8,3,8,0 /* in, local, out, rotating */
mov loc1=rp
mov loc2=gp
ld8 r14=[in0],8
;;
ld8 gp=[in0]
mov r28=in1 /* So we can use stacked pal calling conventions */
mov out0=in1
mov out1=in2
mov out2=in3
mov out3=in4
mov out4=in5
mov out5=in6
mov out6=in7
mov out7=0 /* So we can work with sal calling conventions */
mov b6=r14
;;
br.call.sptk.few rp=b6
;;
rsm psr.i /* disable interrupts */
;;
mov gp=loc2
mov rp=loc1
;;
mov ar.pfs=loc0
br.ret.sptk.many rp
.size __call, . - __call
.endp __call
.text
.globl pal_call
.proc pal_call
pal_call:
alloc loc0 = ar.pfs,4,3,0,0 /* in, local, out, rotating */
mov loc1 = rp
mov loc2 = gp
add r8 = @gprel(pal_entry),gp
add r9 = @gprel(pal_ret),gp
;;
ld8 r14 = [r8]
;;
mov r28 = in0
mov r29 = in1
mov r30 = in2
mov r31 = in3
mov b6 = r14
mov rp = r9
rsm psr.i /* disable interrupts */
;;
br.sptk.few b6
;;
pal_ret:
rsm psr.i /* disable interrupts */
;;
mov gp=loc2
mov rp=loc1
;;
mov ar.pfs=loc0
br.ret.sptk.many rp
File diff suppressed because it is too large Load Diff
+82
View File
@@ -0,0 +1,82 @@
OUTPUT_FORMAT("elf64-ia64-little")
OUTPUT_ARCH(ia64)
ENTRY(_start)
SECTIONS {
. = 0;
__gp = . + 0x200000;
_virt_start = .;
_text = . ;
.text : {
/* Start address of etherboot in the virtual address space */
*(.text)
*(.text.*)
_etext = . ;
_rodata = . ;
. = ALIGN(16);
*(.rodata)
*(.rodata.*)
*(.srodata)
. = ALIGN(16);
pci_drivers = . ;
*(.drivers.pci);
pci_drivers_end = . ;
. = ALIGN(16);
isa_drivers = . ;
*(.drivers.isa);
isa_drivers_end = . ;
. = ALIGN(16);
. = ALIGN(16);
_rela = . ;
*(.rela.text)
*(.rela.rodata)
*(.rela.drivers.pci)
*(.rela.drivers.isa)
*(.rela.drivers.efi)
*(.rela.data)
*(.rela.sdata)
*(.rela.got)
_erela = . ;
. = ALIGN(16);
_erodata = . ;
}
_rela_size = _erela - _rela ;
.data : {
_data = . ;
*(.data)
*(.got.plt)
*(.got)
*(.sdata)
*(.sbss)
*(.scommon)
*(.data.*)
*(.data1)
. = ALIGN(16);
_edata = . ;
}
_bss = . ;
.bss : {
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
}
_ebss = .;
_end = .;
/DISCARD/ : {
*(.comment)
*(.note)
*(.hash)
*(.dynstr)
*(.dynsym)
*(.IA_64.unwind)
*(.IA_64.unwind_info)
*(.IA64_unwind)
*(.IA64_unwind_info)
*(.dynamic)
}
}
+89
View File
@@ -0,0 +1,89 @@
#include "etherboot.h"
#include "timer.h"
#include "sal.h"
#include "pal.h"
static inline unsigned long get_cycles(void)
{
unsigned long result;
__asm__ __volatile__(";;mov %0=ar.itc;;" : "=r"(result));
return result;
}
/* ------ Calibrate the TSC -------
* Time how long it takes to excute a loop that runs in known time.
* And find the convertion needed to get to CLOCK_TICK_RATE
*/
static unsigned long calibrate_cycles(void)
{
unsigned long platform_ticks_per_second, drift_info;
struct pal_freq_ratio itc_ratio;
long result;
result = sal_freq_base(SAL_FREQ_BASE_PLATFORM, &platform_ticks_per_second, &drift_info);
if (result != 0) {
printf("sal_freq_base failed: %lx\n",result);
exit(1);
} else {
result = pal_freq_ratios(0,0,&itc_ratio);
if (result != 0) {
printf("pal_freq_ratios failed: %lx\n", result);
exit(1);
}
}
/* Avoid division by zero */
if (itc_ratio.den == 0)
itc_ratio.den = 1;
return (platform_ticks_per_second *itc_ratio.num)/(itc_ratio.den*TICKS_PER_SEC);
}
static unsigned long clocks_per_tick;
void setup_timers(void)
{
if (!clocks_per_tick) {
clocks_per_tick = calibrate_cycles();
/* Display the CPU Mhz to easily test if the calibration was bad */
printf("ITC %ld Mhz\n", (clocks_per_tick/1000 * TICKS_PER_SEC)/1000);
}
}
unsigned long currticks(void)
{
return get_cycles()/clocks_per_tick;
}
static unsigned long timer_timeout;
static int __timer_running(void)
{
return get_cycles() < timer_timeout;
}
void udelay(unsigned int usecs)
{
unsigned long now;
now = get_cycles();
timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
while(__timer_running());
}
void ndelay(unsigned int nsecs)
{
unsigned long now;
now = get_cycles();
timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
while(__timer_running());
}
void load_timer2(unsigned int timer2_ticks)
{
unsigned long now;
unsigned long clocks;
now = get_cycles();
clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
timer_timeout = now + clocks;
}
int timer2_running(void)
{
return __timer_running();
}
+86
View File
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2000 Hewlett-Packard Co
* Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
*
* 32-bit integer division.
*
* This code is based on the application note entitled "Divide, Square Root
* and Remainder Algorithms for the IA-64 Architecture". This document
* is available as Intel document number 248725-002 or via the web at
* http://developer.intel.com/software/opensource/numerics/
*
* For more details on the theory behind these algorithms, see "IA-64
* and Elementary Functions" by Peter Markstein; HP Professional Books
* (http://www.hp.com/go/retailbooks/)
*/
#ifdef MODULO
# define OP mod
#else
# define OP div
#endif
#ifdef UNSIGNED
# define SGN u
# define EXTEND zxt4
# define INT_TO_FP(a,b) fcvt.xuf.s1 a=b
# define FP_TO_INT(a,b) fcvt.fxu.trunc.s1 a=b
#else
# define SGN
# define EXTEND sxt4
# define INT_TO_FP(a,b) fcvt.xf a=b
# define FP_TO_INT(a,b) fcvt.fx.trunc.s1 a=b
#endif
#define PASTE1(a,b) a##b
#define PASTE(a,b) PASTE1(a,b)
#define NAME PASTE(PASTE(__,SGN),PASTE(OP,si3))
.text
.global NAME
.proc NAME
NAME :
.regstk 2,0,0,0
// Transfer inputs to FP registers.
mov r2 = 0xffdd // r2 = -34 + 65535 (fp reg format bias)
EXTEND in0 = in0 // in0 = a
EXTEND in1 = in1 // in1 = b
;;
setf.sig f8 = in0
setf.sig f9 = in1
#ifdef MODULO
sub in1 = r0, in1 // in1 = -b
#endif
;;
// Convert the inputs to FP, to avoid FP software-assist faults.
INT_TO_FP(f8, f8)
INT_TO_FP(f9, f9)
;;
setf.exp f7 = r2 // f7 = 2^-34
frcpa.s1 f6, p6 = f8, f9 // y0 = frcpa(b)
;;
(p6) fmpy.s1 f8 = f8, f6 // q0 = a*y0
(p6) fnma.s1 f6 = f9, f6, f1 // e0 = -b*y0 + 1
;;
#ifdef MODULO
setf.sig f9 = in1 // f9 = -b
#endif
(p6) fma.s1 f8 = f6, f8, f8 // q1 = e0*q0 + q0
(p6) fma.s1 f6 = f6, f6, f7 // e1 = e0*e0 + 2^-34
;;
#ifdef MODULO
setf.sig f7 = in0
#endif
(p6) fma.s1 f6 = f6, f8, f8 // q2 = e1*q1 + q1
;;
FP_TO_INT(f6, f6) // q = trunc(q2)
;;
#ifdef MODULO
xma.l f6 = f6, f9, f7 // r = q*(-b) + a
;;
#endif
getf.sig r8 = f6 // transfer result to result register
br.ret.sptk.many rp
.size NAME, . - NAME
.endp NAME
+96
View File
@@ -0,0 +1,96 @@
/*
* Copyright (C) 1999-2000, 2002 Hewlett-Packard Co
* Copyright (C) 1999-2000 David Mosberger-Tang <davidm@hpl.hp.com>
*
* 64-bit integer division.
*
* This code is based on the application note entitled "Divide, Square Root
* and Remainder Algorithms for the IA-64 Architecture". This document
* is available as Intel document number 248725-002 or via the web at
* http://developer.intel.com/software/opensource/numerics/
*
* For more details on the theory behind these algorithms, see "IA-64
* and Elementary Functions" by Peter Markstein; HP Professional Books
* (http://www.hp.com/go/retailbooks/)
*/
#ifdef MODULO
# define OP mod
#else
# define OP div
#endif
#ifdef UNSIGNED
# define SGN u
# define INT_TO_FP(a,b) fcvt.xuf.s1 a=b
# define FP_TO_INT(a,b) fcvt.fxu.trunc.s1 a=b
#else
# define SGN
# define INT_TO_FP(a,b) fcvt.xf a=b
# define FP_TO_INT(a,b) fcvt.fx.trunc.s1 a=b
#endif
#define PASTE1(a,b) a##b
#define PASTE(a,b) PASTE1(a,b)
#define NAME PASTE(PASTE(__,SGN),PASTE(OP,di3))
.text
.global NAME
.proc NAME
NAME :
.prologue
.regstk 2,0,0,0
// Transfer inputs to FP registers.
setf.sig f8 = in0
setf.sig f9 = in1
;;
.fframe 16
.save.f 0x20
stf.spill [sp] = f17,-16
// Convert the inputs to FP, to avoid FP software-assist faults.
INT_TO_FP(f8, f8)
;;
.save.f 0x10
stf.spill [sp] = f16
.body
INT_TO_FP(f9, f9)
;;
frcpa.s1 f17, p6 = f8, f9 // y0 = frcpa(b)
;;
(p6) fmpy.s1 f7 = f8, f17 // q0 = a*y0
(p6) fnma.s1 f6 = f9, f17, f1 // e0 = -b*y0 + 1
;;
(p6) fma.s1 f16 = f7, f6, f7 // q1 = q0*e0 + q0
(p6) fmpy.s1 f7 = f6, f6 // e1 = e0*e0
;;
#ifdef MODULO
sub in1 = r0, in1 // in1 = -b
#endif
(p6) fma.s1 f16 = f16, f7, f16 // q2 = q1*e1 + q1
(p6) fma.s1 f6 = f17, f6, f17 // y1 = y0*e0 + y0
;;
(p6) fma.s1 f6 = f6, f7, f6 // y2 = y1*e1 + y1
(p6) fnma.s1 f7 = f9, f16, f8 // r = -b*q2 + a
;;
#ifdef MODULO
setf.sig f8 = in0 // f8 = a
setf.sig f9 = in1 // f9 = -b
#endif
(p6) fma.s1 f17 = f7, f6, f16 // q3 = r*y2 + q2
;;
.restore sp
ldf.fill f16 = [sp], 16
FP_TO_INT(f17, f17) // q = trunc(q3)
;;
#ifdef MODULO
xma.l f17 = f17, f9, f8 // r = q*(-b) + a
;;
#endif
getf.sig r8 = f17 // transfer result to result register
ldf.fill f17 = [sp]
br.ret.sptk.many rp
.size NAME, . - NAME
.endp NAME
+163
View File
@@ -0,0 +1,163 @@
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Note that __sigsetjmp() did NOT flush the register stack. Instead,
we do it here since __longjmp() is usually much less frequently
invoked than __sigsetjmp(). The only difficulty is that __sigsetjmp()
didn't (and wouldn't be able to) save ar.rnat either. This is a problem
because if we're not careful, we could end up loading random NaT bits.
There are two cases:
(i) ar.bsp < ia64_rse_rnat_addr(jmpbuf.ar_bsp)
ar.rnat contains the desired bits---preserve ar.rnat
across loadrs and write to ar.bspstore
(ii) ar.bsp >= ia64_rse_rnat_addr(jmpbuf.ar_bsp)
The desired ar.rnat is stored in
ia64_rse_rnat_addr(jmpbuf.ar_bsp). Load those
bits into ar.rnat after setting ar.bspstore. */
# define pPos p6 /* is rotate count positive? */
# define pNeg p7 /* is rotate count negative? */
/* longjmp(__jmp_buf buf, int val) */
.text
.global longjmp
.proc longjmp
longjmp:
alloc r8=ar.pfs,2,1,0,0
mov r27=ar.rsc
add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr
;;
ld8 r8=[r2],-16 // r8 <- orig_jmp_buf_addr
mov r10=ar.bsp
and r11=~0x3,r27 // clear ar.rsc.mode
;;
flushrs // flush dirty regs to backing store (must be first in insn grp)
ld8 r23=[r2],8 // r23 <- jmpbuf.ar_bsp
sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf
;;
ld8 r25=[r2] // r25 <- jmpbuf.ar_unat
extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f
;;
cmp.lt pNeg,pPos=r8,r0
mov r2=in0
;;
(pPos) mov r16=r8
(pNeg) add r16=64,r8
(pPos) sub r17=64,r8
(pNeg) sub r17=r0,r8
;;
mov ar.rsc=r11 // put RSE in enforced lazy mode
shr.u r8=r25,r16
add r3=8,in0 // r3 <- &jmpbuf.r1
shl r9=r25,r17
;;
or r25=r8,r9
;;
mov r26=ar.rnat
mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12)
;;
ld8.fill.nta sp=[r2],16 // r12 (sp)
ld8.fill.nta gp=[r3],16 // r1 (gp)
dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp)
;;
ld8.nta r16=[r2],16 // caller's unat
ld8.nta r17=[r3],16 // fpsr
;;
ld8.fill.nta r4=[r2],16 // r4
ld8.fill.nta r5=[r3],16 // r5 (gp)
cmp.geu p8,p0=r10,r11 // p8 <- (ar.bsp >= jmpbuf.ar_bsp)
;;
ld8.fill.nta r6=[r2],16 // r6
ld8.fill.nta r7=[r3],16 // r7
;;
mov ar.unat=r16 // restore caller's unat
mov ar.fpsr=r17 // restore fpsr
;;
ld8.nta r16=[r2],16 // b0
ld8.nta r17=[r3],16 // b1
;;
(p8) ld8 r26=[r11] // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp)
mov ar.bspstore=r23 // restore ar.bspstore
;;
ld8.nta r18=[r2],16 // b2
ld8.nta r19=[r3],16 // b3
;;
ld8.nta r20=[r2],16 // b4
ld8.nta r21=[r3],16 // b5
;;
ld8.nta r11=[r2],16 // ar.pfs
ld8.nta r22=[r3],56 // ar.lc
;;
ld8.nta r24=[r2],32 // pr
mov b0=r16
;;
ldf.fill.nta f2=[r2],32
ldf.fill.nta f3=[r3],32
mov b1=r17
;;
ldf.fill.nta f4=[r2],32
ldf.fill.nta f5=[r3],32
mov b2=r18
;;
ldf.fill.nta f16=[r2],32
ldf.fill.nta f17=[r3],32
mov b3=r19
;;
ldf.fill.nta f18=[r2],32
ldf.fill.nta f19=[r3],32
mov b4=r20
;;
ldf.fill.nta f20=[r2],32
ldf.fill.nta f21=[r3],32
mov b5=r21
;;
ldf.fill.nta f22=[r2],32
ldf.fill.nta f23=[r3],32
mov ar.lc=r22
;;
ldf.fill.nta f24=[r2],32
ldf.fill.nta f25=[r3],32
cmp.eq p8,p9=0,in1
;;
ldf.fill.nta f26=[r2],32
ldf.fill.nta f27=[r3],32
mov ar.pfs=r11
;;
ldf.fill.nta f28=[r2],32
ldf.fill.nta f29=[r3],32
;;
ldf.fill.nta f30=[r2]
ldf.fill.nta f31=[r3]
(p8) mov r8=1
mov ar.rnat=r26 // restore ar.rnat
;;
mov ar.rsc=r27 // restore ar.rsc
(p9) mov r8=in1
invala // virt. -> phys. regnum mapping may change
mov pr=r24,-1
br.ret.sptk.few b0
.size longjmp, . - longjmp
.endp longjmp
+244
View File
@@ -0,0 +1,244 @@
/* Optimized version of the standard memmove() function.
This file is part of the GNU C Library.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
Contributed by Dan Pop <Dan.Pop@cern.ch>.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/* Return: dest
Inputs:
in0: dest
in1: src
in2: byte count
The core of the function is the memcpy implementation used in memcpy.S.
When bytes have to be copied backwards, only the easy case, when
all arguments are multiples of 8, is optimised.
In this form, it assumes little endian mode. For big endian mode,
sh1 must be computed using an extra instruction: sub sh1 = 64, sh1
or the UM.be bit should be cleared at the beginning and set at the end. */
#define OP_T_THRES 16
#define OPSIZ 8
#define adest r15
#define saved_pr r17
#define saved_lc r18
#define dest r19
#define src r20
#define len r21
#define asrc r22
#define tmp2 r23
#define tmp3 r24
#define tmp4 r25
#define ptable r26
#define ploop56 r27
#define loopaddr r28
#define sh1 r29
#define loopcnt r30
#define value r31
#define LOOP(shift) \
.align 32 ; \
.loop##shift##: \
(p[0]) ld8 r[0] = [asrc], 8 ; /* w1 */ \
(p[MEMLAT+1]) st8 [dest] = value, 8 ; \
(p[MEMLAT]) shrp value = r[MEMLAT], r[MEMLAT+1], shift ; \
nop.b 0 ; \
nop.b 0 ; \
br.ctop.sptk .loop##shift ; \
br.cond.sptk .cpyfew ; /* deal with the remaining bytes */
#define MEMLAT 21
#define Nrot (((2*MEMLAT+3) + 7) & ~7)
.text
.global memmove, memcpy
.proc memove
memcpy:
memmove:
.prologue
alloc r2 = ar.pfs, 3, Nrot - 3, 0, Nrot
.rotr r[MEMLAT + 2], q[MEMLAT + 1]
.rotp p[MEMLAT + 2]
mov ret0 = in0 // return value = dest
.save pr, saved_pr
mov saved_pr = pr // save the predicate registers
.save ar.lc, saved_lc
mov saved_lc = ar.lc // save the loop counter
.body
or tmp3 = in0, in1 ;; // tmp3 = dest | src
or tmp3 = tmp3, in2 // tmp3 = dest | src | len
mov dest = in0 // dest
mov src = in1 // src
mov len = in2 // len
sub tmp2 = r0, in0 // tmp2 = -dest
cmp.eq p6, p0 = in2, r0 // if (len == 0)
(p6) br.cond.spnt .restore_and_exit;;// return dest;
and tmp4 = 7, tmp3 // tmp4 = (dest | src | len) & 7
cmp.le p6, p0 = dest, src // if dest <= src it's always safe
(p6) br.cond.spnt .forward // to copy forward
add tmp3 = src, len;;
cmp.lt p6, p0 = dest, tmp3 // if dest > src && dest < src + len
(p6) br.cond.spnt .backward // we have to copy backward
.forward:
shr.u loopcnt = len, 4 ;; // loopcnt = len / 16
cmp.ne p6, p0 = tmp4, r0 // if ((dest | src | len) & 7 != 0)
(p6) br.cond.sptk .next // goto next;
// The optimal case, when dest, src and len are all multiples of 8
and tmp3 = 0xf, len
mov pr.rot = 1 << 16 // set rotating predicates
mov ar.ec = MEMLAT + 1 ;; // set the epilog counter
cmp.ne p6, p0 = tmp3, r0 // do we have to copy an extra word?
adds loopcnt = -1, loopcnt;; // --loopcnt
(p6) ld8 value = [src], 8;;
(p6) st8 [dest] = value, 8 // copy the "odd" word
mov ar.lc = loopcnt // set the loop counter
cmp.eq p6, p0 = 8, len
(p6) br.cond.spnt .restore_and_exit;;// the one-word special case
adds adest = 8, dest // set adest one word ahead of dest
adds asrc = 8, src ;; // set asrc one word ahead of src
nop.b 0 // get the "golden" alignment for
nop.b 0 // the next loop
.l0:
(p[0]) ld8 r[0] = [src], 16
(p[0]) ld8 q[0] = [asrc], 16
(p[MEMLAT]) st8 [dest] = r[MEMLAT], 16
(p[MEMLAT]) st8 [adest] = q[MEMLAT], 16
br.ctop.dptk .l0 ;;
mov pr = saved_pr, -1 // restore the predicate registers
mov ar.lc = saved_lc // restore the loop counter
br.ret.sptk.many b0
.next:
cmp.ge p6, p0 = OP_T_THRES, len // is len <= OP_T_THRES
and loopcnt = 7, tmp2 // loopcnt = -dest % 8
(p6) br.cond.spnt .cpyfew // copy byte by byte
;;
cmp.eq p6, p0 = loopcnt, r0
(p6) br.cond.sptk .dest_aligned
sub len = len, loopcnt // len -= -dest % 8
adds loopcnt = -1, loopcnt // --loopcnt
;;
mov ar.lc = loopcnt
.l1: // copy -dest % 8 bytes
ld1 value = [src], 1 // value = *src++
;;
st1 [dest] = value, 1 // *dest++ = value
br.cloop.dptk .l1
.dest_aligned:
and sh1 = 7, src // sh1 = src % 8
and tmp2 = -8, len // tmp2 = len & -OPSIZ
and asrc = -8, src // asrc = src & -OPSIZ -- align src
shr.u loopcnt = len, 3 // loopcnt = len / 8
and len = 7, len;; // len = len % 8
adds loopcnt = -1, loopcnt // --loopcnt
addl tmp4 = @ltoff(.table), gp
addl tmp3 = @ltoff(.loop56), gp
mov ar.ec = MEMLAT + 1 // set EC
mov pr.rot = 1 << 16;; // set rotating predicates
mov ar.lc = loopcnt // set LC
cmp.eq p6, p0 = sh1, r0 // is the src aligned?
(p6) br.cond.sptk .src_aligned
add src = src, tmp2 // src += len & -OPSIZ
shl sh1 = sh1, 3 // sh1 = 8 * (src % 8)
ld8 ploop56 = [tmp3] // ploop56 = &loop56
ld8 ptable = [tmp4];; // ptable = &table
add tmp3 = ptable, sh1;; // tmp3 = &table + sh1
mov ar.ec = MEMLAT + 1 + 1 // one more pass needed
ld8 tmp4 = [tmp3];; // tmp4 = loop offset
sub loopaddr = ploop56,tmp4 // loopadd = &loop56 - loop offset
ld8 r[1] = [asrc], 8;; // w0
mov b6 = loopaddr;;
br b6 // jump to the appropriate loop
LOOP(8)
LOOP(16)
LOOP(24)
LOOP(32)
LOOP(40)
LOOP(48)
LOOP(56)
.src_aligned:
.l3:
(p[0]) ld8 r[0] = [src], 8
(p[MEMLAT]) st8 [dest] = r[MEMLAT], 8
br.ctop.dptk .l3
.cpyfew:
cmp.eq p6, p0 = len, r0 // is len == 0 ?
adds len = -1, len // --len;
(p6) br.cond.spnt .restore_and_exit ;;
mov ar.lc = len
.l4:
ld1 value = [src], 1
;;
st1 [dest] = value, 1
br.cloop.dptk .l4 ;;
.restore_and_exit:
mov pr = saved_pr, -1 // restore the predicate registers
mov ar.lc = saved_lc // restore the loop counter
br.ret.sptk.many b0
// In the case of a backward copy, optimise only the case when everything
// is a multiple of 8, otherwise copy byte by byte. The backward copy is
// used only when the blocks are overlapping and dest > src.
.backward:
shr.u loopcnt = len, 3 // loopcnt = len / 8
add src = src, len // src points one byte past the end
add dest = dest, len ;; // dest points one byte past the end
mov ar.ec = MEMLAT + 1 // set the epilog counter
mov pr.rot = 1 << 16 // set rotating predicates
adds loopcnt = -1, loopcnt // --loopcnt
cmp.ne p6, p0 = tmp4, r0 // if ((dest | src | len) & 7 != 0)
(p6) br.cond.sptk .bytecopy ;; // copy byte by byte backward
adds src = -8, src // src points to the last word
adds dest = -8, dest // dest points to the last word
mov ar.lc = loopcnt;; // set the loop counter
.l5:
(p[0]) ld8 r[0] = [src], -8
(p[MEMLAT]) st8 [dest] = r[MEMLAT], -8
br.ctop.dptk .l5
br.cond.sptk .restore_and_exit
.bytecopy:
adds src = -1, src // src points to the last byte
adds dest = -1, dest // dest points to the last byte
adds loopcnt = -1, len;; // loopcnt = len - 1
mov ar.lc = loopcnt;; // set the loop counter
.l6:
(p[0]) ld1 r[0] = [src], -1
(p[MEMLAT]) st1 [dest] = r[MEMLAT], -1
br.ctop.dptk .l6
br.cond.sptk .restore_and_exit
.table:
data8 0 // dummy entry
data8 .loop56 - .loop8
data8 .loop56 - .loop16
data8 .loop56 - .loop24
data8 .loop56 - .loop32
data8 .loop56 - .loop40
data8 .loop56 - .loop48
data8 .loop56 - .loop56
.size memmove, . - memove
.endp memmove
+133
View File
@@ -0,0 +1,133 @@
/*
* Copyright (C) 1999-2002 Hewlett-Packard Co.
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
*
* This file is part of the ELILO, the EFI Linux boot loader.
*
* ELILO is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* ELILO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ELILO; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Please check out the elilo.txt for complete documentation on how
* to use this program.
*
* This code is derived from the Linux/ia64 source code.
*/
/*
*
* Optimized version of the standard memset() function
*
* Return: none
*
* Inputs:
* in0: address of buffer
* in1: byte value to use for storing
* in2: length of the buffer
*
*/
// arguments
//
#define buf r32
#define val r33
#define len r34
//
// local registers
//
#define saved_pfs r14
#define cnt r18
#define buf2 r19
#define saved_lc r20
#define tmp r21
.text
.global memset
.proc memset
memset:
.prologue
.save ar.pfs, saved_pfs
alloc saved_pfs=ar.pfs,3,0,0,0 // cnt is sink here
cmp.eq p8,p0=r0,len // check for zero length
.save ar.lc, saved_lc
mov saved_lc=ar.lc // preserve ar.lc (slow)
;;
.body
adds tmp=-1,len // br.ctop is repeat/until
tbit.nz p6,p0=buf,0 // odd alignment
(p8) br.ret.spnt.few rp
cmp.lt p7,p0=16,len // if len > 16 then long memset
mux1 val=val,@brcst // prepare value
(p7) br.cond.dptk.few long_memset
;;
mov ar.lc=tmp // initialize lc for small count
;; // avoid RAW and WAW on ar.lc
1: // worst case 15 cyles, avg 8 cycles
st1 [buf]=val,1
br.cloop.dptk.few 1b
;; // avoid RAW on ar.lc
mov ar.lc=saved_lc
mov ar.pfs=saved_pfs
br.ret.sptk.few rp // end of short memset
// at this point we know we have more than 16 bytes to copy
// so we focus on alignment
long_memset:
(p6) st1 [buf]=val,1 // 1-byte aligned
(p6) adds len=-1,len;; // sync because buf is modified
tbit.nz p6,p0=buf,1
;;
(p6) st2 [buf]=val,2 // 2-byte aligned
(p6) adds len=-2,len;;
tbit.nz p6,p0=buf,2
;;
(p6) st4 [buf]=val,4 // 4-byte aligned
(p6) adds len=-4,len;;
tbit.nz p6,p0=buf,3
;;
(p6) st8 [buf]=val,8 // 8-byte aligned
(p6) adds len=-8,len;;
shr.u cnt=len,4 // number of 128-bit (2x64bit) words
;;
cmp.eq p6,p0=r0,cnt
adds tmp=-1,cnt
(p6) br.cond.dpnt.few .dotail // we have less than 16 bytes left
;;
adds buf2=8,buf // setup second base pointer
mov ar.lc=tmp
;;
2: // 16bytes/iteration
st8 [buf]=val,16
st8 [buf2]=val,16
br.cloop.dptk.few 2b
;;
.dotail: // tail correction based on len only
tbit.nz p6,p0=len,3
;;
(p6) st8 [buf]=val,8 // at least 8 bytes
tbit.nz p6,p0=len,2
;;
(p6) st4 [buf]=val,4 // at least 4 bytes
tbit.nz p6,p0=len,1
;;
(p6) st2 [buf]=val,2 // at least 2 bytes
tbit.nz p6,p0=len,0
mov ar.lc=saved_lc
;;
(p6) st1 [buf]=val // only 1 byte left
br.ret.dptk.few rp
.endp memset
+84
View File
@@ -0,0 +1,84 @@
#include "etherboot.h"
#include "sal.h"
#include "pal.h"
struct fptr pal_entry;
/*
* Note that some of these calls use a static-register only calling
* convention which has nothing to do with the regular calling
* convention.
*/
#define PAL_CACHE_FLUSH 1 /* flush i/d cache */
#define PAL_CACHE_INFO 2 /* get detailed i/d cache info */
#define PAL_CACHE_INIT 3 /* initialize i/d cache */
#define PAL_CACHE_SUMMARY 4 /* get summary of cache heirarchy */
#define PAL_MEM_ATTRIB 5 /* list supported memory attributes */
#define PAL_PTCE_INFO 6 /* purge TLB info */
#define PAL_VM_INFO 7 /* return supported virtual memory features */
#define PAL_VM_SUMMARY 8 /* return summary on supported vm features */
#define PAL_BUS_GET_FEATURES 9 /* return processor bus interface features settings */
#define PAL_BUS_SET_FEATURES 10 /* set processor bus features */
#define PAL_DEBUG_INFO 11 /* get number of debug registers */
#define PAL_FIXED_ADDR 12 /* get fixed component of processors's directed address */
#define PAL_FREQ_BASE 13 /* base frequency of the platform */
#define PAL_FREQ_RATIOS 14 /* ratio of processor, bus and ITC frequency */
#define PAL_PERF_MON_INFO 15 /* return performance monitor info */
#define PAL_PLATFORM_ADDR 16 /* set processor interrupt block and IO port space addr */
#define PAL_PROC_GET_FEATURES 17 /* get configurable processor features & settings */
#define PAL_PROC_SET_FEATURES 18 /* enable/disable configurable processor features */
#define PAL_RSE_INFO 19 /* return rse information */
#define PAL_VERSION 20 /* return version of PAL code */
#define PAL_MC_CLEAR_LOG 21 /* clear all processor log info */
#define PAL_MC_DRAIN 22 /* drain operations which could result in an MCA */
#define PAL_MC_EXPECTED 23 /* set/reset expected MCA indicator */
#define PAL_MC_DYNAMIC_STATE 24 /* get processor dynamic state */
#define PAL_MC_ERROR_INFO 25 /* get processor MCA info and static state */
#define PAL_MC_RESUME 26 /* Return to interrupted process */
#define PAL_MC_REGISTER_MEM 27 /* Register memory for PAL to use during MCAs and inits */
#define PAL_HALT 28 /* enter the low power HALT state */
#define PAL_HALT_LIGHT 29 /* enter the low power light halt state*/
#define PAL_COPY_INFO 30 /* returns info needed to relocate PAL */
#define PAL_CACHE_LINE_INIT 31 /* init tags & data of cache line */
#define PAL_PMI_ENTRYPOINT 32 /* register PMI memory entry points with the processor */
#define PAL_ENTER_IA_32_ENV 33 /* enter IA-32 system environment */
#define PAL_VM_PAGE_SIZE 34 /* return vm TC and page walker page sizes */
#define PAL_MEM_FOR_TEST 37 /* get amount of memory needed for late processor test */
#define PAL_CACHE_PROT_INFO 38 /* get i/d cache protection info */
#define PAL_REGISTER_INFO 39 /* return AR and CR register information*/
#define PAL_SHUTDOWN 40 /* enter processor shutdown state */
#define PAL_PREFETCH_VISIBILITY 41
#define PAL_COPY_PAL 256 /* relocate PAL procedures and PAL PMI */
#define PAL_HALT_INFO 257 /* return the low power capabilities of processor */
#define PAL_TEST_PROC 258 /* perform late processor self-test */
#define PAL_CACHE_READ 259 /* read tag & data of cacheline for diagnostic testing */
#define PAL_CACHE_WRITE 260 /* write tag & data of cacheline for diagnostic testing */
#define PAL_VM_TR_READ 261 /* read contents of translation register */
/*
* Get the ratios for processor frequency, bus frequency and interval timer to
* to base frequency of the platform
*/
long pal_freq_ratios(struct pal_freq_ratio *proc_ratio,
struct pal_freq_ratio *bus_ratio, struct pal_freq_ratio *itc_ratio)
{
struct freq_ratios {
long status;
struct pal_freq_ratio proc_ratio;
struct pal_freq_ratio bus_ratio;
struct pal_freq_ratio itc_ratio;
};
struct freq_ratios result;
extern struct freq_ratios pal_call(unsigned long which, ...);
result = pal_call(PAL_FREQ_RATIOS, 0, 0, 0);
if (proc_ratio)
*proc_ratio = result.proc_ratio;
if (bus_ratio)
*bus_ratio = result.bus_ratio;
if (itc_ratio)
*itc_ratio = result.itc_ratio;
return result.status;
}
+62
View File
@@ -0,0 +1,62 @@
#include "etherboot.h"
#include "pci.h"
#include "sal.h"
int pcibios_read_config_byte(unsigned int bus, unsigned int devfn, unsigned int reg, uint8_t *rvalue)
{
unsigned long value;
long result;
result = sal_pci_config_read(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 1, &value);
*rvalue = value;
return result;
}
int pcibios_read_config_word(unsigned int bus, unsigned int devfn, unsigned int reg, uint16_t *rvalue)
{
unsigned long value;
long result;
result = sal_pci_config_read(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 2, &value);
*rvalue = value;
return result;
}
int pcibios_read_config_dword(unsigned int bus, unsigned int devfn, unsigned int reg, uint32_t *rvalue)
{
unsigned long value;
long result;
result = sal_pci_config_read(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 4, &value);
*rvalue = value;
return result;
}
int pcibios_write_config_byte(unsigned int bus, unsigned int devfn, unsigned int reg, uint8_t value)
{
return sal_pci_config_write(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 1, value);
}
int pcibios_write_config_word(unsigned int bus, unsigned int devfn, unsigned int reg, uint16_t value)
{
return sal_pci_config_write(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 2, value);
}
int pcibios_write_config_dword(unsigned int bus, unsigned int devfn, unsigned int reg, uint32_t value)
{
return sal_pci_config_write(PCI_SAL_ADDRESS(0,bus, 0, devfn, reg), 4, value);
}
/* So far I have not see a non-zero PCI_BUS_OFFSET
* and an AML parser to get it much to much trouble.
*/
#ifndef PCI_BUS_OFFSET
#define PCI_BUS_OFFSET 0
#endif
unsigned long pcibios_bus_base(unsigned int bus)
{
return PCI_BUS_OFFSET;
}
void find_pci(int type, struct pci_device *dev)
{
/* Should I check for sal functions being present? */
return scan_pci_bus(type, dev);
}
+133
View File
@@ -0,0 +1,133 @@
/* reloc.S - position independent IA-64 ELF shared object relocator
Copyright (C) 1999 Hewlett-Packard Co.
Contributed by David Mosberger <davidm@hpl.hp.com>.
Copyright (C) 2002 Eric Biederman sponsored by Linux Networx
This file is part of etherboot.
This file was derived from reloc_ia64.S from GNU-EFI, the GNU EFI development environment.
GNU EFI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU EFI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU EFI; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*
* This is written in assembly because the entire code needs to be position
* independent. Note that the compiler does not generate code that's position
* independent by itself because it relies on the global offset table being
* relocated.
*
* This code assumes the code was compiled with -mconstant-gp -mauto-pic -static -shared
* Which generates position independent code, but not position indepedent data.
* This code assumes in the linker script the rela entries are bracked with:
* _rela, _erela and _rela_size gives the total size of the rela entries.
* This gives a much smaller binary than when compiled as a true shared object.
*
* This code assumes the original shared object was initially relocated,
* So that it only needs to apply changes for the new address the code is linked
* at.
*/
.text
.psr abi64
.psr lsb
.lsb
#define ST_VALUE_OFF 8 /* offset of st_value in elf sym */
#define RET_SUCCESS 0
#define RET_LOAD_ERROR 1
#define R_IA64_NONE 0
#define R_IA64_REL64MSB 0x6e
#define R_IA64_REL64LSB 0x6f
#define R_IA64_DIR64MSB 0x26
#define R_IA64_DIR64LSB 0x27
#define R_IA64_FPTR64MSB 0x46
#define R_IA64_FPTR64LSB 0x47
#define delta in0 /* Chaing in load address (address of .text) */
#define ldbase r15
#define target r16
#define val r17
#define rela r18
#define relasz r19
#define relaent r20
#define addr r21
#define r_info r22
#define r_offset r23
#define r_type r25
#define Pmore p6
#define Pnone p6
#define Prel p7
#define Pdir p8
.global _relocate
_relocate:
alloc r2=ar.pfs,1,0,0,0
add rela=@gprel(_rela),gp
add ldbase=@gprel(_text),gp
add r3=@ltoff(_rela_size),gp
;;
ld8 relasz = [r3]
mov relaent=24
br.sptk.few apply_relocs
apply_loop:
ld8 r_offset = [rela]
add addr = 8,rela
sub relasz = relasz,relaent
;;
ld8 r_info = [addr], 8
;;
add target = ldbase, r_offset
add rela = rela,relaent
extr.u r_type = r_info, 0, 32
;;
cmp.eq Pnone,p0 = R_IA64_NONE, r_type
cmp.eq Prel,p0 = R_IA64_REL64LSB, r_type
cmp.eq Pdir,p0 = R_IA64_DIR64LSB, r_type /* Needed? */
;;
(Pnone) br.cond.sptk.few apply_relocs
(Prel) br.cond.sptk.few apply_REL64
(Pdir) br.cond.sptk.few apply_DIR64 /* Needed? */
;;
apply_error:
mov r8 = RET_LOAD_ERROR
br.ret.sptk.few rp
apply_REL64:
apply_DIR64:
ld8 val = [target]
;;
add val = val, delta
;;
st8 [target] = val
;;
/* fall through to apply_relocs */
apply_relocs:
cmp.ltu Pmore,p0=0,relasz
(Pmore) br.cond.sptk.few apply_loop
;;
mov r8 = RET_SUCCESS
br.ret.sptk.few rp
.size _relocate, . - _relocate
.endp _relocate
+92
View File
@@ -0,0 +1,92 @@
/* Temporarily ignore the stack, as I am still using efi's stack */
#define newbase in0
#define base loc2
#define newgp loc3
#define len loc4
.explicit
.globl relocate_to
.proc relocate_to
relocate_to:
/* In incoming variable the new base addres of etherboot. */
alloc loc0=ar.pfs,1,5,3,0 /* in, local, out, rotating */
mov loc1=rp
/* Compute the current location of _text */
/* Compute the new gp value */
add base=@gprel(_text),gp
add len =@gprel(_end),gp
movl newgp=@gprel(_text)
;;
sub newgp=newbase,newgp /* gp = _text - @gprel(_text) */
sub len=len,base
;;
/* Copy etherboot to the new location */
mov out0=newbase
mov out1=base
mov out2=len
br.call.sptk.few rp=memcpy
;;
/* Jump to my __relocate_to in the new location */
movl r14=@gprel(__relocate_to)
;;
add r14=r14,newgp
;;
mov b6=r14
;;
br.cond.sptk.few b6
;;
__relocate_to:
/* I am at the new location set the newgp as the default */
mov gp=newgp
;;
/* New apply relocations to the new copy */
sub out0=newbase,base
br.call.sptk.few rp=_relocate
;;
/* Lookup restart_etherboot */
add out0=@gprel(restart_etherboot),gp
;;
/* Adjust the gp and return address.
* NOTE: This only works when the setjmp can modify it's caller's gp
* address. Essentially this means etherboot must be compiled with
* compiled with -mconstant-gp, though an inline version of setjmp might work.
*/
add r14=0x40,out0
add r16=0x08,out0
;;
ld8 r15=[r14]
ld8 r17=[r16]
;;
sub r15=r15,base
sub r17=r17,base
;;
add r15=r15,newbase
add r17=r17,newbase
;;
st8 [r14]=r15
st8 [r16]=r17
;;
mov out1=256
br.call.sptk.few rp=longjmp
/* And just in case lonjmp returns... */
/* Adjust my return address and return */
sub loc1=loc1,base
;;
add loc1=loc1,newbase
;;
mov ar.pfs=loc0
mov rp=loc1
;;
br.ret.sptk.few rp
.size relocate_to, . - relocate_to
.endp relocate_to
+278
View File
@@ -0,0 +1,278 @@
#include "etherboot.h"
#include "sal.h"
struct sal_entry_base {
uint8_t entry_type;
#define SAL_TYPE_ENTRYPOINT 0
#define SAL_TYPE_MEMORY 1
#define SAL_TYPE_PLATFORM_FEATURES 2
#define SAL_TYPE_TRANSLATION_REGISTER 3
#define SAL_TYPE_PURGE_DOMAIN 4
#define SAL_TYPE_AP_WAKEUP 5
};
struct sal_entry_point_descriptor {
uint8_t entry_type;
uint8_t reserved[7];
uint64_t pal_proc;
uint64_t sal_proc;
uint64_t sal_gp;
uint8_t reserved2[16];
};
struct sal_memory_descriptor {
uint8_t entry_type;
uint8_t sal_needs_virt_mapping;
uint8_t mem_attr;
#define MEM_ATTR_WB 0
#define MEM_ATTR_UC 8
#define MEM_ATTR_UCE 9
#define MEM_ATTR_WC 10
uint8_t access_rights;
uint8_t mem_attr_support;
#define MEM_ATTR_SUPPORTS_WB 1
#define MEM_ATTR_SUPPORTS_UC 2
#define MEM_ATTR_SUPPORTS_UCE 4
#define MEM_ATTR_SUPPORTS_WC 8
uint8_t reserved;
uint8_t mem_type;
#define MEM_TYPE_RAM 0
#define MEM_TYPE_MIO 1
#define MEM_TYPE_SAPIC 2
#define MEM_TYPE_PIO 3
#define MEM_TYPE_FIRMWARE 4
#define MEM_TYPE_BAD_RAM 9
#define MEM_TYPE_BLACK_HOLE 10
uint8_t mem_usage;
#define MEM_USAGE_UNSPECIFIED 0
#define MEM_USAGE_PAL_CODE 1
#define MEM_USAGE_BOOT_SERVICES_CODE 2
#define MEM_USAGE_BOOT_SERVICES_DATA 3
#define MEM_USAGE_RUNTIME_SERVICES_CODE 4
#define MEM_USAGE_RUNTIME_SERVICES_DATA 5
#define MEM_USAGE_IA32_OPTION_ROM 6
#define MEM_USAGE_IA32_SYSTEM_ROM 7
#define MEM_USAGE_ACPI_RECLAIM_MEMORY 8
#define MEM_USAGE_ACPI_NVS_MEMORY 9
#define MEM_USAGE_SAL_PMI_CODE 10
#define MEM_USAGE_SAL_PMI_DATA 11
#define MEM_USAGE_FIRMWARE_RESERVED_RAM 12
#define MEM_USAGE_CPU_TO_IO 0
uint64_t phys_address;
uint32_t pages; /* In 4k pages */
uint32_t reserved2;
uint8_t oem_reserved[8];
};
struct sal_platform_features {
uint8_t entry_type;
uint8_t feature_list;
#define SAL_FEATURE_BUS_LOCK 1
#define SAL_FEATURE_PLATFORM_REDIRECTION_HINT 2
#define SAL_FEATURE_PROCESSOR_REDIRECTION_HINT 3
uint8_t reserved[14];
};
struct sal_translation_register {
uint8_t entry_type;
uint8_t tr_type;
#define SAL_ITR 0
#define SAL_DTR 1
uint8_t tr_number;
uint8_t reserved[5];
uint64_t virtual_address;
uint64_t page_size;
uint8_t reserved2[8];
};
struct sal_purge_translation_cache_coherency_domain {
uint8_t entry_type;
uint8_t reserved[3];
uint32_t coherence_domain_count;
uint64_t coherence_domain_addr;
};
struct sal_ap_wakeup_descriptor {
uint8_t entry_type;
uint8_t wakeup_mechanism;
uint8_t reserved[6];
uint64_t interrupt;
};
struct sal_entry {
union {
struct sal_entry_base base;
struct sal_entry_point_descriptor entry_point;
struct sal_memory_descriptor mem;
struct sal_platform_features features;
struct sal_translation_register tr;
struct sal_purge_translation_cache_coherency_domain purge;
struct sal_ap_wakeup_descriptor ap_wakeup;
};
};
struct sal_system_table {
uint8_t signature[4]; /* SST_ */
uint32_t table_length;
uint16_t sal_rev;
uint16_t entry_count;
uint8_t checksum;
uint8_t reserved1[7];
uint16_t sal_a_version;
uint16_t sal_b_version;
uint8_t oem_id[32];
uint8_t product_id[32];
uint8_t reserved2[8];
struct sal_entry entry[0];
};
static struct sal_system_table *sal;
struct fptr sal_entry;
int parse_sal_system_table(void *table)
{
struct sal_system_table *salp = table;
uint8_t *ptr;
uint8_t checksum;
struct sal_entry *entry;
unsigned i;
if (memcmp(salp->signature, "SST_", 4) != 0) {
return 0;
}
ptr = table;
checksum = 0;
for(i = 0; i < salp->table_length; i++) {
checksum += ptr[i];
}
if (checksum != 0) {
return 0;
}
#if 0
printf("SALA: %hx SALB: %hx\n",
salp->sal_a_version,
salp->sal_b_version);
printf("SAL OEM: ");
for(i = 0; i < sizeof(salp->oem_id); i++) {
uint8_t ch = salp->oem_id[i];
if (ch == 0)
break;
printf("%c", ch);
}
printf("\n");
printf("SAL PRODUCT: ");
for(i = 0; i < sizeof(salp->product_id); i++) {
uint8_t ch = salp->product_id[i];
if (ch == 0)
break;
printf("%c", ch);
}
printf("\n");
#endif
sal = salp;
pal_entry.entry = 0;
pal_entry.gp = 0;
sal_entry.entry = 0;
sal_entry.gp = 0;
entry = sal->entry;
i = 0;
while(i < salp->entry_count) {
unsigned long size = 0;
switch(entry->base.entry_type) {
case SAL_TYPE_ENTRYPOINT:
size = sizeof(entry->entry_point);
pal_entry.entry = entry->entry_point.pal_proc;
sal_entry.entry = entry->entry_point.sal_proc;
sal_entry.gp = entry->entry_point.sal_gp;
break;
case SAL_TYPE_MEMORY:
size = sizeof(entry->mem);
break;
case SAL_TYPE_PLATFORM_FEATURES:
size = sizeof(entry->features);
break;
case SAL_TYPE_TRANSLATION_REGISTER:
size = sizeof(entry->tr);
break;
case SAL_TYPE_PURGE_DOMAIN:
size = sizeof(entry->purge);
break;
case SAL_TYPE_AP_WAKEUP:
size = sizeof(entry->ap_wakeup);
break;
default:
break;
}
entry = (struct sal_entry *)(((char *)entry) + size);
i++;
}
return 1;
}
#define SAL_SET_VECTORS 0x01000000
#define SAL_GET_STATE_INFO 0x01000001
#define SAL_GET_STATE_INFO_SIZE 0x01000002
#define SAL_CLEAR_STATE_INFO 0x01000003
#define SAL_MC_RENDEZ 0x01000004
#define SAL_MC_SET_PARAMS 0x01000005
#define SAL_REGISTER_PHYSICAL_ADDR 0x01000006
#define SAL_CACHE_FLUSH 0x01000008
#define SAL_CACHE_INIT 0x01000009
#define SAL_PCI_CONFIG_READ 0x01000010
#define SAL_PCI_CONFIG_WRITE 0x01000011
#define SAL_FREQ_BASE 0x01000012
#define SAL_UPDATE_PAL 0x01000020
/*
* Now define a couple of inline functions for improved type checking
* and convenience.
*/
long sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
unsigned long *drift_info)
{
struct {
long status;
unsigned long ticks_per_second;
unsigned long drift_info;
} result, __call(void *,...);
result = __call(&sal_entry, SAL_FREQ_BASE, which, 0, 0, 0, 0, 0, 0);
*ticks_per_second = result.ticks_per_second;
*drift_info = result.drift_info;
return result.status;
}
/* Read from PCI configuration space */
long sal_pci_config_read (
unsigned long pci_config_addr, unsigned long size, unsigned long *value)
{
struct {
long status;
unsigned long value;
} result, __call(void *,...);
result = __call(&sal_entry, SAL_PCI_CONFIG_READ, pci_config_addr, size, 0, 0, 0, 0, 0);
if (value)
*value = result.value;
return result.status;
}
/* Write to PCI configuration space */
long sal_pci_config_write (
unsigned long pci_config_addr, unsigned long size, unsigned long value)
{
struct {
long status;
} result, __call(void *,...);
result = __call(&sal_entry, SAL_PCI_CONFIG_WRITE, pci_config_addr, size, value, 0, 0, 0, 0);
return result.status;
}
+173
View File
@@ -0,0 +1,173 @@
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
The layout of the jmp_buf is as follows. This is subject to change
and user-code should never depend on the particular layout of
jmp_buf!
offset: description:
------- ------------
0x000 stack pointer (r12) ; unchangeable (see _JMPBUF_UNWINDS)
0x008 r1 (gp)
0x010 caller's unat
0x018 fpsr
0x020 r4
0x028 r5
0x030 r6
0x038 r7
0x040 rp (b0)
0x048 b1
0x050 b2
0x058 b3
0x060 b4
0x068 b5
0x070 ar.pfs
0x078 ar.lc
0x080 pr
0x088 ar.bsp ; unchangeable (see __longjmp.S)
0x090 ar.unat
0x098 &__jmp_buf ; address of the jmpbuf (needed to locate NaT bits in unat)
0x0a0 f2
0x0b0 f3
0x0c0 f4
0x0d0 f5
0x0e0 f16
0x0f0 f17
0x100 f18
0x110 f19
0x120 f20
0x130 f21
0x130 f22
0x140 f23
0x150 f24
0x160 f25
0x170 f26
0x180 f27
0x190 f28
0x1a0 f29
0x1b0 f30
0x1c0 f31 */
/* The following two entry points are the traditional entry points: */
.text
.global setjmp
.proc setjmp
setjmp:
alloc r8=ar.pfs,2,0,0,0
mov in1=1
br.cond.sptk.many __sigsetjmp
.size setjmp, . - setjmp
.endp setjmp
/* __sigsetjmp(__jmp_buf buf, int savemask) */
__sigsetjmp:
#if 0
.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
#endif
alloc loc1=ar.pfs,2,2,2,0
mov r16=ar.unat
;;
mov r17=ar.fpsr
mov r2=in0
add r3=8,in0
;;
st8.spill.nta [r2]=sp,16 // r12 (sp)
st8.spill.nta [r3]=gp,16 // r1 (gp)
;;
st8.nta [r2]=r16,16 // save caller's unat
st8.nta [r3]=r17,16 // save fpsr
add r8=0xa0,in0
;;
st8.spill.nta [r2]=r4,16 // r4
st8.spill.nta [r3]=r5,16 // r5
add r9=0xb0,in0
;;
stf.spill.nta [r8]=f2,32
stf.spill.nta [r9]=f3,32
mov loc0=rp
.body
;;
stf.spill.nta [r8]=f4,32
stf.spill.nta [r9]=f5,32
mov r17=b1
;;
stf.spill.nta [r8]=f16,32
stf.spill.nta [r9]=f17,32
mov r18=b2
;;
stf.spill.nta [r8]=f18,32
stf.spill.nta [r9]=f19,32
mov r19=b3
;;
stf.spill.nta [r8]=f20,32
stf.spill.nta [r9]=f21,32
mov r20=b4
;;
stf.spill.nta [r8]=f22,32
stf.spill.nta [r9]=f23,32
mov r21=b5
;;
stf.spill.nta [r8]=f24,32
stf.spill.nta [r9]=f25,32
mov r22=ar.lc
;;
stf.spill.nta [r8]=f26,32
stf.spill.nta [r9]=f27,32
mov r24=pr
;;
stf.spill.nta [r8]=f28,32
stf.spill.nta [r9]=f29,32
;;
stf.spill.nta [r8]=f30
stf.spill.nta [r9]=f31
st8.spill.nta [r2]=r6,16 // r6
st8.spill.nta [r3]=r7,16 // r7
;;
mov r23=ar.bsp
mov r25=ar.unat
mov out0=in0
st8.nta [r2]=loc0,16 // b0
st8.nta [r3]=r17,16 // b1
mov out1=in1
;;
st8.nta [r2]=r18,16 // b2
st8.nta [r3]=r19,16 // b3
;;
st8.nta [r2]=r20,16 // b4
st8.nta [r3]=r21,16 // b5
;;
st8.nta [r2]=loc1,16 // ar.pfs
st8.nta [r3]=r22,16 // ar.lc
;;
st8.nta [r2]=r24,16 // pr
st8.nta [r3]=r23,16 // ar.bsp
;;
st8.nta [r2]=r25 // ar.unat
st8.nta [r3]=in0 // &__jmp_buf
mov r8=0
mov rp=loc0
mov ar.pfs=loc1
br.ret.sptk.many rp
.endp __sigsetjmp
+28
View File
@@ -0,0 +1,28 @@
.text
.align 4
.proc _start
.globl _start
_start:
{
alloc loc0 = ar.pfs,1,2,1,0 /* in, local, out, rotating */
mov loc1 = rp
mov r14 = ip /* Get the address of _start */
}
movl r15 = @gprel(_start)
;;
sub gp = r14,r15
;;
rsm psr.i /* disable interrupts */
;;
add out0 = @gprel(_text),gp
br.call.sptk.few rp = _relocate
;;
cmp.eq p6,p7 = r0,r8 /* r8 == SUCCESS? */
mov ar.pfs = loc0
mov rp = loc1
;;
(p6) br.cond.sptk.few main
(p7) br.ret.sptk.few rp
.size _start, . - _start
.endp _start
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
#ifndef ETHERBOOT_BITS_BYTESWAP_H
#define ETHERBOOT_BITS_BYTESWAP_H
static inline uint64_t __ia64_bswap_64(uint64_t x)
{
uint64_t result;
__asm__ volatile(
"mux1 %0=%1,@rev" :
"=r" (result)
: "r" (x));
return result;
}
#define __bswap_constant_16(x) \
((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
(((uint16_t)(x) & 0xff00) >> 8)))
#define __bswap_constant_32(x) \
((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
(((uint32_t)(x) & 0x0000ff00U) << 8) | \
(((uint32_t)(x) & 0x00ff0000U) >> 8) | \
(((uint32_t)(x) & 0xff000000U) >> 24)))
#define __bswap_16(x) \
(__builtin_constant_p(x) ? \
__bswap_constant_16(x) : \
(__ia64_bswap_64(x) >> 48))
#define __bswap_32(x) \
(__builtin_constant_p(x) ? \
__bswap_constant_32(x) : \
(__ia64_bswap_64(x) >> 32))
#endif /* ETHERBOOT_BITS_BYTESWAP_H */
+6
View File
@@ -0,0 +1,6 @@
#ifndef IA64_BITS_CPU_H
#define IA64_BITS_CPU_H
#define cpu_setup() do {} while(0)
#endif /* IA64_BITS_CPU_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef IA64_BITS_ELF_H
#define IA64_BITS_ELF_H
/* ELF Defines for the current architecture */
#define EM_CURRENT EM_IA_64
#define ELFDATA_CURRENT ELFDATA2LSB
#define ELF_CHECK_ARCH(x) \
((x).e_machine == EM_CURRENT)
#endif /* IA64_BITS_ELF_H */
+6
View File
@@ -0,0 +1,6 @@
#ifndef ETHERBOOT_BITS_ENDIAN_H
#define ETHERBOOT_BITS_ENDIAN_H
#define __BYTE_ORDER __LITTLE_ENDIAN
#endif /* ETHERBOOT_BITS_ENDIAN_H */
+6
View File
@@ -0,0 +1,6 @@
#ifndef ETHERBOOT_BITS_STRING_H
#define ETHERBOOT_BITS_STRING_H
/* define inline optimized string functions here */
#endif /* ETHERBOOT_BITS_STRING_H */
+12
View File
@@ -0,0 +1,12 @@
#ifndef ETHERBOOT_IA64_HOOKS_H
#define ETHERBOOT_IA64_HOOKS_H
#include <stdarg.h>
void arch_main(in_call_data_t *data, va_list params);
void arch_on_exit(int status);
void arch_relocate_to(unsigned long addr);
#define arch_relocated_from(old_addr) do {} while(0)
#endif /* ETHERBOOT_IA64_HOOKS_H */
+228
View File
@@ -0,0 +1,228 @@
#ifndef ETHERBOOT_IO_H
#define ETHERBOOT_IO_H
/* Don't require identity mapped physical memory,
* osloader.c is the only valid user at the moment.
*/
static inline unsigned long virt_to_phys(volatile const void *virt_addr)
{
return ((unsigned long)virt_addr);
}
static inline void *phys_to_virt(unsigned long phys_addr)
{
return (void *)(phys_addr);
}
/* virt_to_bus converts an addresss inside of etherboot [_start, _end]
* into a memory address cards can use.
*/
#define virt_to_bus virt_to_phys
/* bus_to_virt reverses virt_to_bus, the address must be output
* from virt_to_bus to be valid. This function does not work on
* all bus addresses.
*/
#define bus_to_virt phys_to_virt
/* ioremap converts a random 32bit bus address into something
* etherboot can access.
*/
static inline void *ioremap(unsigned long bus_addr, unsigned long length __unused)
{
return bus_to_virt(bus_addr);
}
/* iounmap cleans up anything ioremap had to setup */
static inline void iounmap(void *virt_addr __unused)
{
return;
}
/* In physical mode the offset of uncached pages */
#define PHYS_BASE (0x8000000000000000UL)
/* Memory mapped IO primitives, we avoid the cache... */
static inline uint8_t readb(unsigned long addr)
{
return *((volatile uint8_t *)(PHYS_BASE | addr));
}
static inline uint16_t readw(unsigned long addr)
{
return *((volatile uint16_t *)(PHYS_BASE | addr));
}
static inline uint32_t readl(unsigned long addr)
{
return *((volatile uint32_t *)(PHYS_BASE | addr));
}
static inline uint64_t readq(unsigned long addr)
{
return *((volatile uint64_t *)(PHYS_BASE | addr));
}
static inline void writeb(uint8_t val, unsigned long addr)
{
*((volatile uint8_t *)(PHYS_BASE | addr)) = val;
}
static inline void writew(uint16_t val, unsigned long addr)
{
*((volatile uint16_t *)(PHYS_BASE | addr)) = val;
}
static inline void writel(uint32_t val, unsigned long addr)
{
*((volatile uint32_t *)(PHYS_BASE | addr)) = val;
}
static inline void writeq(uint64_t val, unsigned long addr)
{
*((volatile uint64_t *)(PHYS_BASE | addr)) = val;
}
static inline void memcpy_fromio(void *dest, unsigned long src, size_t n)
{
size_t i;
uint8_t *dp = dest;
for(i = 0; i < n; i++) {
*dp = readb(src);
dp++;
src++;
}
}
static inline void memcpy_toio(unsigned long dest , const void *src, size_t n)
{
size_t i;
const uint8_t *sp = src;
for(i = 0; i < n; i++) {
writeb(*sp, dest);
sp++;
dest++;
}
}
/* IO space IO primitives, Itanium has a strange architectural mapping... */
extern unsigned long io_base;
#define __ia64_mf_a() __asm__ __volatile__ ("mf.a" ::: "memory")
#define __ia64_io_addr(port) ((void *)(PHYS_BASE | io_base | (((port) >> 2) << 12) | ((port) & 0xfff)))
static inline uint8_t inb(unsigned long port)
{
uint8_t result;
result = *((volatile uint8_t *)__ia64_io_addr(port));
__ia64_mf_a();
return result;
}
static inline uint16_t inw(unsigned long port)
{
uint8_t result;
result = *((volatile uint16_t *)__ia64_io_addr(port));
__ia64_mf_a();
return result;
}
static inline uint32_t inl(unsigned long port)
{
uint32_t result;
result = *((volatile uint32_t *)__ia64_io_addr(port));
__ia64_mf_a();
return result;
}
static inline void outb(uint8_t val, unsigned long port)
{
*((volatile uint8_t *)__ia64_io_addr(port)) = val;
__ia64_mf_a();
}
static inline void outw(uint16_t val, unsigned long port)
{
*((volatile uint16_t *)__ia64_io_addr(port)) = val;
__ia64_mf_a();
}
static inline void outl(uint32_t val, unsigned long port)
{
*((volatile uint32_t *)__ia64_io_addr(port)) = val;
__ia64_mf_a();
}
static inline void insb(unsigned long port, void *dst, unsigned long count)
{
volatile uint8_t *addr = __ia64_io_addr(port);
uint8_t *dp = dst;
__ia64_mf_a();
while(count--)
*dp++ = *addr;
__ia64_mf_a();
}
static inline void insw(unsigned long port, void *dst, unsigned long count)
{
volatile uint16_t *addr = __ia64_io_addr(port);
uint16_t *dp = dst;
__ia64_mf_a();
while(count--)
*dp++ = *addr;
__ia64_mf_a();
}
static inline void insl(unsigned long port, void *dst, unsigned long count)
{
volatile uint32_t *addr = __ia64_io_addr(port);
uint32_t *dp = dst;
__ia64_mf_a();
while(count--)
*dp++ = *addr;
__ia64_mf_a();
}
static inline void outsb(unsigned long port, void *src, unsigned long count)
{
const uint8_t *sp = src;
volatile uint8_t *addr = __ia64_io_addr(port);
while (count--)
*addr = *sp++;
__ia64_mf_a();
}
static inline void outsw(unsigned long port, void *src, unsigned long count)
{
const uint16_t *sp = src;
volatile uint16_t *addr = __ia64_io_addr(port);
while (count--)
*addr = *sp++;
__ia64_mf_a();
}
static inline void outsl(unsigned long port, void *src, unsigned long count)
{
const uint32_t *sp = src;
volatile uint32_t *addr = __ia64_io_addr(port);
while (count--)
*addr = *sp++;
__ia64_mf_a();
}
static inline unsigned long ia64_get_kr0(void)
{
unsigned long r;
asm volatile ("mov %0=ar.k0" : "=r"(r));
return r;
}
#endif /* ETHERBOOT_IO_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef LATCH_H
#define LATCH_H
#define TICKS_PER_SEC (1000UL)
/* Fixed timer interval used for calibrating a more precise timer */
#define LATCHES_PER_SEC 10
void sleep_latch(void);
#endif /* LATCH_H */
+57
View File
@@ -0,0 +1,57 @@
#ifndef LIMITS_H
#define LIMITS_H 1
/* Number of bits in a `char' */
#define CHAR_BIT 8
/* Minimum and maximum values a `signed char' can hold */
#define SCHAR_MIN (-128)
#define SCHAR_MAX 127
/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
#define UCHAR_MAX 255
/* Minimum and maximum values a `char' can hold */
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
/* Minimum and maximum values a `signed short int' can hold */
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */
#define USHRT_MAX 65535
/* Minimum and maximum values a `signed int' can hold */
#define INT_MIN (-INT_MAX - 1)
#define INT_MAX 2147483647
/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
#define UINT_MAX 4294967295U
/* Minimum and maximum values a `signed int' can hold */
#define INT_MIN (-INT_MAX - 1)
#define INT_MAX 2147483647
/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
#define UINT_MAX 4294967295U
/* Minimum and maximum values a `signed long' can hold */
#define LONG_MAX 9223372036854775807L
#define LONG_MIN (-LONG_MAX - 1L)
/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */
#define ULONG_MAX 18446744073709551615UL
/* Minimum and maximum values a `signed long long' can hold */
#define LLONG_MAX 9223372036854775807LL
#define LLONG_MIN (-LONG_MAX - 1LL)
/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */
#define ULLONG_MAX 18446744073709551615ULL
#endif /* LIMITS_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef IA64_PAL_H
#define IA64_PAL_H
struct pal_freq_ratio {
unsigned long den : 32, num : 32; /* numerator & denominator */
};
extern long pal_freq_ratios(struct pal_freq_ratio *proc_ratio,
struct pal_freq_ratio *bus_ratio, struct pal_freq_ratio *itc_ratio);
#endif /* IA64_PAL_H */
+29
View File
@@ -0,0 +1,29 @@
#ifndef IA64_SAL_H
#define IA64_SAL_H
struct fptr {
unsigned long entry;
unsigned long gp;
};
extern struct fptr sal_entry;
extern struct fptr pal_entry;
extern int parse_sal_system_table(void *table);
#define SAL_FREQ_BASE_PLATFORM 0
#define SAL_FREQ_BASE_INTERVAL_TIMER 1
#define SAL_FREQ_BASE_REALTIME_CLOCK 2
long sal_freq_base (unsigned long which, unsigned long *ticks_per_second,
unsigned long *drift_info);
#define PCI_SAL_ADDRESS(seg, bus, dev, fn, reg) \
((unsigned long)(seg << 24) | (unsigned long)(bus << 16) | \
(unsigned long)(dev << 11) | (unsigned long)(fn << 8) | \
(unsigned long)(reg))
long sal_pci_config_read (
unsigned long pci_config_addr, unsigned long size, unsigned long *value);
long sal_pci_config_write (
unsigned long pci_config_addr, unsigned long size, unsigned long value);
#endif /* IA64_SAL_H */
+13
View File
@@ -0,0 +1,13 @@
#ifndef ETHERBOOT_SETJMP_H
#define ETHERBOOT_SETJMP_H
/* Define a type for use by setjmp and longjmp */
#define JBLEN 70
typedef long jmp_buf[JBLEN] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
extern int setjmp (jmp_buf env);
extern void longjmp (jmp_buf env, int val);
#endif /* ETHERBOOT_SETJMP_H */
+16
View File
@@ -0,0 +1,16 @@
#ifndef STDINT_H
#define STDINT_H
typedef unsigned long size_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long int64_t;
#endif /* STDINT_H */
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/perl -w
#
# Program to apply an efi header to an ia64 etherboot file.
#
# GPL Eric Biederman 2002
#
use strict;
use bytes;
main(@ARGV);
sub usage
{
my ($err) = @_;
print STDERR $err , "\n";
die "Usage $0 prrefix file bss_size\n";
}
sub main
{
my ($prefix_name, $suffix_name, $bss_size) = @_;
usage("No prefix") unless (defined($prefix_name));
usage("No suffix") unless (defined($suffix_name));
usage("No bss size") unless (defined($bss_size));
open(PREFIX, "<$prefix_name") or die "Cannot open $prefix_name";
open(SUFFIX, "<$suffix_name") or die "Cannot open $suffix_name";
$/ = undef;
my $prefix = <PREFIX>; close(PREFIX);
my $suffix = <SUFFIX>; close(SUFFIX);
# Payload sizes.
my $payload_size = length($suffix);
my $payload_bss = $bss_size;
# Update the image size
my $hdr_off = unpack("V",substr($prefix, 0x3c, 4));
my $image_size_off = 0x050 + $hdr_off;
my $img_mem_size_off = 0x0c0 + $hdr_off;
my $img_size_off = 0x0c8 + $hdr_off;
my $image_size = unpack("V", substr($prefix, $image_size_off, 4));
my $img_mem_size = unpack("V", substr($prefix, $img_mem_size_off, 4));
my $img_size = unpack("V", substr($prefix, $img_size_off, 4));
$image_size += $payload_size + $payload_bss;
$img_mem_size += $payload_size + $payload_bss;
$img_size += $payload_size;
substr($prefix, $image_size_off, 4) = pack("V", $image_size);
substr($prefix, $img_mem_size_off, 4) = pack("V", $img_mem_size);
substr($prefix, $img_size_off, 4) = pack("V", $img_size);
#print(STDERR "image_size: $image_size\n");
#print(STDERR "img_mem_size: $img_mem_size\n");
#print(STDERR "img_size: $img_size\n");
print $prefix;
print $suffix;
}
@@ -0,0 +1,198 @@
#!/usr/bin/perl -w
#
# Program to apply an unnrv2b decompressor header to an ia64 etherboot file.
#
# GPL Eric Biederman 2002
#
use strict;
use bytes;
main(@ARGV);
sub usage
{
my ($err) = @_;
print STDERR $err , "\n";
die "Usage $0 prefix file\n";
}
sub getbits
{
my ($bundle, $start, $size) = @_;
# Compute the mask
my $mask = 0xffffffff;
$mask = $mask >> (32 - $size);
# Compute the substring, and shift
my ($first, $end, $count, $shift);
$first = int($start / 8);
$end = int(($start + $size + 7)/8);
$count = $end - $first;
$shift = $start % 8;
# Compute the unpack type
my $type;
if ($count == 1) {
$type = "C"
}
elsif ($count == 2) {
$type = "v";
}
elsif (($count >= 3) && ($count <= 4)) {
$type = "V";
}
else {
die "bad count $count";
}
# Now compute the value
my $val = (unpack($type, substr($bundle, $first, $count)) >> $shift) & $mask;
# Now return the value
return $val;
}
sub putbits
{
my ($bundle, $start, $size, $val) = @_;
# Compute the mask
my $mask = 0xffffffff;
$mask >>= 32 - $size;
# Compute the substring, and shift
my ($first, $end, $count, $shift);
$first = int($start / 8);
$end = int(($start + $size + 7)/8);
$count = $end - $first;
$shift = $start % 8;
# Compute the unpack type
my $type;
if ($count == 1) {
$type = "C"
}
elsif ($count == 2) {
$type = "v";
}
elsif (($count >= 3) && ($count <= 4)) {
$type = "V";
}
else {
die "bad count $count";
}
# Adjust the mask
$mask <<= $shift;
# Now set the value, preserving the untouched bits
substr($bundle, $first, $count) =
pack($type,
((unpack($type, substr($bundle, $first, $count)) & ~$mask) |
(($val << $shift) & $mask)));
# Now return the new value;
return $bundle;
}
sub main
{
my ($prefix_name, $suffix_name) = @_;
usage("No prefix") unless (defined($prefix_name));
usage("No suffix") unless (defined($suffix_name));
open(PREFIX, "<$prefix_name") or die "Cannot open $prefix_name";
open(SUFFIX, "<$suffix_name") or die "Cannot open $suffix_name";
$/ = undef;
my $prefix = <PREFIX>; close(PREFIX);
my $suffix = <SUFFIX>; close(SUFFIX);
# Payload sizes
my $prefix_len = length($prefix);
my $suffix_len = length($suffix);
my $payload_size = $suffix_len;
my $uncompressed_offset = ($prefix_len + $suffix_len + 15) & ~15;
my $pad = $uncompressed_offset - ($prefix_len + $suffix_len);
# Itaninum instruction bundle we will be updating
# 0 - 4 template == 5
# 5 - 45 slot 0 M-Unit
# 46 - 86 slot 1 L-Unit
# 87 - 127 slot 2 X-Unit
# Itaninum instruction format
# 40 - 37 Major opcode
# ...
#
# slot 1
# 0 - 40 [41] imm-41
# 10 - 40 [31] imm-41-hi
# 0 - 9 [10] imm-41-lo
# slot 2
# 0 - 5 [6] qp
# 6 - 12 [7] r1
# 13 - 19 [7] imm-7b
# 20 [1] vc
# 21 [1] immc
# 22 - 26 [5] imm-5c
# 27 - 35 [9] imm-9d
# 36 [1] imm0
# 37 - 40 [4] major opcode
#
# major opcode should be 6
# Update the image size
my $uncompressed_offset_bundle_off = 16;
my $bundle = substr($prefix, $uncompressed_offset_bundle_off, 16);
my $template = getbits($bundle, 0, 5);
my $op1_base = 46;
my $op2_base = 87;
my $major_opcode = getbits($bundle, 37 + $op2_base, 4);
if (($template != 5) ||
($major_opcode != 6)) {
die "unknown second bundle cannot patch";
}
die "uncompressed_offset to big!\n" if ($uncompressed_offset > 0xffffffff);
my $immhi = 0;
my $immlo = $uncompressed_offset;
my $imm0 = ($immhi >> 31) & ((1 << 1) - 1);
my $imm41_hi = ($immhi >> 0) & ((1 << 31) - 1);
my $imm41_lo = ($immlo >> 22) & ((1 << 10) - 1);
my $immc = ($immlo >> 21) & ((1 << 1) - 1);
my $imm5c = ($immlo >> 16) & ((1 << 5) - 1);
my $imm9d = ($immlo >> 7) & ((1 << 9) - 1);
my $imm7b = ($immlo >> 0) & ((1 << 7) - 1);
$bundle = putbits($bundle, 10 + $op1_base, 31, $imm41_hi);
$bundle = putbits($bundle, 0 + $op1_base, 10, $imm41_lo);
$bundle = putbits($bundle, 36 + $op2_base, 1 , $imm0);
$bundle = putbits($bundle, 27 + $op2_base, 9 , $imm9d);
$bundle = putbits($bundle, 22 + $op2_base, 5 , $imm5c);
$bundle = putbits($bundle, 21 + $op2_base, 1 , $immc);
$bundle = putbits($bundle, 13 + $op2_base, 7 , $imm7b);
substr($prefix, $uncompressed_offset_bundle_off, 16) = $bundle;
#print (STDERR "prefix: $prefix_len\n");
#print (STDERR "suffix: $suffix_len\n");
#print (STDERR "pad: $pad\n");
#print (STDERR "uncompressed_offset: $uncompressed_offset\n");
print $prefix;
print $suffix;
# Pad the resulting image by a few extra bytes...
print pack("C", 0) x $pad;
}
+195
View File
@@ -0,0 +1,195 @@
#include "elf.h"
.explicit
.section ".hdrs", "a"
/* First the DOS file header */
dos_header:
.byte 'M', 'Z' /* Signature */
.short dos_program_end - dos_program /* Length of image mod 512 bytes*/
.short 0x0001 /* Length of image in 512 byte pages */ /* FIXME */
.short 0x0000 /* Number of relocation items following header */
.short (dos_header_end - dos_header)/16 /* Size of header in 16 byte paragraphs */
.short 0x0001 /* Minimum number of paragraphs needed to run image */
.short 0x0001 /* Maximum number of paragraphs program would like */
.short 0x0000 /* Initial SS */
.short 0x00b8 /* Initial SP */
.short 0x0000 /* Negative checksum of image */
.short 0x0000 /* Initial IP */
.short 0x0000 /* Initial CS */
.short 0x0010 /* Offset in EXEC of first relocation item */
.short 0x0000 /* Overlay number */
.balign 16
dos_header_end:
dos_program:
.byte 0xdb /* retf */
.balign 16
dos_program_end:
.org 0x3c
.byte pe_signature - dos_header, 0x00, 0x00, 0x00
.org 0x40 /* NOTE: set this to 0x80 for debugging, 0x40 otherwise */
pe_signature:
.byte 'P', 'E', 0, 0
coff_header:
#define IMAGE_MACHINE_IA64 0x0200
coff_machine: .short IMAGE_MACHINE_IA64
coff_nsections: .short (section_headers_end - section_headers)/40
coff_timdat: .int 1038168747 /* Sun Nov 24 12:12:27 2002 */
coff_symptr: .int 0x00000000
coff_nsyms: .int 0x00000000
coff_opthdr: .short pe_end - pe_header
#define CF_RELOC_STRIPPED 0x0001
#define CF_EXECUTABLE 0x0002
#define CF_LINE_STRIPPED 0x0004
#define CF_LOCAL_STRIPPED 0x0008
#define CF_DEBUG_STRIPPED 0x0206
coff_flags: .short CF_EXECUTABLE | CF_LINE_STRIPPED | CF_LOCAL_STRIPPED | CF_DEBUG_STRIPPED
/* Option header */
pe_header:
pe_magic: .short 0x020b /* 020b or 010b? */
pe_linker: .byte 0x02, 0x38
pe_text_size: .int _text_size
pe_data_size: .int _data_size
pe_bss_size: .int _bss_size
pe_entry: .int _start_plabel_rva
pe_text_base: .int _text_rva
pe_image_base: .quad _image_base
pe_sec_align: .int _sect_align
pe_file_align: .int _file_align
pe_os_major: .short 0
pe_os_minor: .short 0
pe_image_major: .short 0
pe_image_minro: .short 0
pe_sub_major: .short 0
pe_sub_minor: .short 0
pe_reserved: .int 0
pe_image_size: .int _image_size
pe_hdrs_size: .int _hdrs_size
pe_checksum: .int 0 /* FIXME how do I compute the checksum, unnecessary */
#define SUBSYS_EFI_APP 10
#define SUBSYS_EFI_BOOT_SERVICE_DRIVER 11
#define SUBSYS_EFI_RUNTIME_DRIVER 12
pe_subsys: .short SUBSYS_EFI_APP
pe_dll_flags: .short 0
pe_stack_res: .quad 0
pe_stack_commit:.quad 0
pe_heap_res: .quad 0
pe_heap_commit: .quad 0
pe_ld_flags: .int 0
pe_rvas: .int (rvas_end - rvas_start)/8
rvas_start:
rva_0_rva: .int 0
rva_0_size: .int 0
rva_1_rva: .int 0
rva_1_size: .int 0
rva_2_rva: .int 0
rva_2_size: .int 0
rva_3_rva: .int 0
rva_3_size: .int 0
rva_4_rva: .int 0
rva_4_size: .int 0
rva_5_rva: .int _reloc_rva
rva_5_size: .int __reloc_size
rvas_end:
pe_end:
section_headers:
#define SCN_CNT_CODE 0x00000020
#define SCN_CNT_INITIALIZED_DATA 0x00000040
#define SCN_CNT_UNINITIALIZED_DATA 0x00000080
#define SCN_MEM_DISCARDABLE 0x02000000
#define SCN_MEM_SHARED 0x10000000
#define SCN_MEM_EXECUTE 0x20000000
#define SCN_MEM_READ 0x40000000
#define SCN_MEM_WRITE 0x80000000
sec1_name: .byte '.', 'i', 'm', 'g', 0 , 0, 0, 0
sec1_virt_size: .int _img_mem_size
sec1_virt_addr: .int _img_rva
sec1_file_size: .int _img_size
sec1_file_off: .int _img_off
sec1_reloc_off: .int 0
sec1_line_off: .int 0
sec1_reloc_cnt: .short 0
sec1_line_cnt: .short 0
sec1_flags: .int SCN_CNT_CODE | SCN_CNT_INITIALIZED_DATA \
| SCN_MEM_EXECUTE | SCN_MEM_READ | SCN_MEM_WRITE
section_headers_end:
.text
.psr abi64
.psr lsb
.global _start
_start:
{
alloc r8=ar.pfs,2,0,0,0
mov gp=ip /* Get the address of _start/_text/__gp */
}
;;
add r14=@gprel(n1_desc),gp
add r15=@gprel(n2_desc),gp
add r16=@gprel(bhdr),gp
;;
st8 [r14]=in0
st8 [r15]=in1
;;
mov ar.pfs=r8
;;
mov r32=r16
;;
br.sptk.few _payload_start
.data
.global _start_plabel
.balign 16
_start_plabel:
.quad _start
.quad 0 /* I don't need a gp value... */
/* hand-crafted bhdr and parameters */
.balign 16
bhdr:
b_signature: .int 0x0E1FB007
b_size: .int bhdr_end - bhdr
b_checksum: .short 0
b_records: .short 3
/* A NOP note to 64bit align later data */
.balign 4
n0_namesz: .int 0
n0_descsz: .int 0
n0_type: .int EBN_NOP
.balign 4
n1_namesz: .int 10
n1_descsz: .int 8
n1_type: .int EB_IA64_IMAGE_HANDLE
n1_name: .asciz "Etherboot"
.balign 4
n1_desc: .quad 0
.balign 4
n2_namesz: .int 10
n2_descsz: .int 8
n2_type: .int EB_IA64_SYSTAB
n2_name: .asciz "Etherboot"
.balign 4
n2_desc: .quad 0
bhdr_end:
/* hand-craft a .reloc section for the plabel */
#define IMAGE_REL_BASED_ABS 0
#define IMAGE_REL_BASED_DIR64 10
.section ".reloc", "a"
.int _start_plabel_rva // PAGE RVA
.int 12 // Block Size (2*4+2*2)
.short (IMAGE_REL_BASED_DIR64<<12) + 0 // reloc for plabel's entry point
.short (IMAGE_REL_BASED_ABS <<12) + 0 // dummy reloc for good alignment
+91
View File
@@ -0,0 +1,91 @@
/* OUTPUT_FORMAT("binary") */
OUTPUT_FORMAT("elf64-ia64-little")
OUTPUT_ARCH(ia64)
ENTRY(_start_plabel)
_sect_align = 16; /* normally 512 */
_file_align = 16; /* normally 4096 */
/* Symbols for hardcoding the payload and _bss size, with apply_efi_prefix
* there is no need to set these, and in will get confused if these are not 0.
*/
_payload_size = 0;
_payload_bss = 0;
SECTIONS {
/* We can arbitrarily set image base to anything we want,
* but efi does not honor it, so it is a pointless exercise.
* So we just set the start address to 0.
*/
. = 0;
_link_base = . ;
_image_base = . ;
.hdrs : {
_hdrs = . ;
*(.hdrs)
. = ALIGN(_file_align) ;
_ehdrs = . ;
}
. = ALIGN(_sect_align);
.img : {
_img = . ;
_text = . ;
__gp = . ;
*(.text)
_etext = .;
. = ALIGN(16);
_data = . ;
*(.data)
_edata = .;
. = ALIGN(16);
_reloc = . ;
*(.reloc)
__ereloc = . ;
_ereloc = . ;
. = ALIGN(16);
/* . = ALIGN(_file_align) ; */
}
_payload_start = . ;
. = . + _payload_size ;
_payload_end = . ;
_eimg = . ;
. = ALIGN(_sect_align) ;
_bss = . ;
.bss : {
*(.bss)
. = . + _payload_bss;
}
_ebss = . ;
_end = . ;
/DISCARD/ : {
*(*)
}
_hdrs_size = _ehdrs - _hdrs;
_hdrs_off = 0;
_text_size = _etext - _text ;
_text_rva = _text - _image_base ;
_text_off = _text - _link_base;
_data_size = _edata - _data ;
_data_rva = _data - _image_base;
_data_off = _data - _link_base;
__reloc_size = __ereloc - _reloc ;
_reloc_size = _ereloc - _reloc ;
_reloc_rva = _reloc - _image_base;
_reloc_off = _reloc - _link_base;
_bss_size = _ebss - _bss;
_bss_rva = _bss - _image_base;
_img_size = _eimg - _img ;
_img_rva = _img - _image_base;
_img_off = _img - _link_base;
_img_mem_size = _ebss - _img;
_image_size = _ebss - _link_base ;
_start_plabel_rva = _start_plabel - _image_base;
}
+196
View File
@@ -0,0 +1,196 @@
/*
* Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
* Copyright (C) 2002 Eric Biederman
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Originally this code was part of ucl the data compression library
* for upx the ``Ultimate Packer of eXecutables''.
*
* - Converted to gas assembly, and refitted to work with etherboot.
* Eric Biederman 20 Aug 2002
*
* - Converted to functional ia64 assembly (Can this get smaller?)
* Eric Biederman 5 Dec 2002
*/
.text
.globl _start
_start:
/* See where I am running, and compute gp */
{
/* Do no call alloc here as I do not know how many argument
* registers are being passed through the decompressor, and if I report
* to few the unreported registers may get stomped.
*
* Instead just explicitly get the value of ar.pfs.
*/
mov r17=0
mov r8=ar.pfs
mov gp = ip /* The linker scripts sets gp at _start */
}
{.mlx
movl r9=0x123456789abcdef0 /* Get uncompressed_offset into r9 */
}
;;
{
add r14 = @gprel(payload + 4),gp
add r15 = r9,gp
mov r16=1 /* last_m_off = 1 */
}
{
mov r20 = 0xd00
add r21 = r9,gp
br.sptk.few decompr_loop_n2b
}
/* ------------- DECOMPRESSION -------------
Input:
r8 - ar.pfs
r14 - source
r15 - dest
r16 - 1
r17 - (buffer) 0
r20 - 0xd00 (constant)
r21 - start address
Usage:
r9 - scratch register for memory copies
r18 - scratch register for getbit
r19 - scratch register for loads and stores
Output:
r2 - 0
r3 - 0
*/
getbit:
add r18 = r17,r17
;;
cmp.ne p8,p0 = r0,r18
cmp.leu p6,p7 = r18,r17
;;
mov r17 = r18
(p8) br.cond.sptk.few getbit_end
/* Do a unaligned 64bit load */
;;
ld1 r17 = [r14],1
;;
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,8,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,16,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,24,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,32,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,40,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,48,8
ld1 r18 = [r14],1
;;
dep r17 = r18,r17,56,8
;;
add r18 = r17,r17,1
;;
cmp.leu p6,p7=r18,r17
;;
mov r17=r18
;;
getbit_end:
br.ret.sptk.few b6
decompr_literals_n2b:
ld1 r19 = [r14],1
;;
st1 [r15] = r19,1
;;
decompr_loop_n2b:
br.call.sptk.few b6 = getbit
;;
(p6) br.cond.sptk.few decompr_literals_n2b
(p7) add r2 = 1,r0 /* m_off = 1 */
;;
loop1_n2b:
br.call.sptk.few b6 = getbit
;;
(p6) add r2 = r2,r2,1 /* m_off = m_off*2 + getbit() */
(p7) add r2 = r2,r2
br.call.sptk.few b6 = getbit
;;
(p7) br.cond.sptk.few loop1_n2b /* while(!getbit()) */
;;
mov r3 = r0
cmp.eq p6,p0 = 2,r2
add r2 = -3,r2
(p6) br.cond.sptk.few decompr_ebpeax_n2b /* if (m_off == 2) goto decompr_ebpeax_n2b ? */
;;
ld1 r19 = [r14],1
shl r2 = r2,8
;;
dep r2 = r19,r2,0,8 /* m_off = (m_off - 3)*256 + src[ilen++] */
;;
cmp4.eq p6,p0 = -1,r2 /* if (m_off == 0xffffffff) goto decomp_end_n2b */
;;
(p6) br.cond.sptk.few decompr_end_n2b
mov r16 = r2 /* last_m_off = m_off */
;;
decompr_ebpeax_n2b:
br.call.sptk.few b6 = getbit
;;
(p6) add r3 = r3,r3,1 /* m_len = getbit() */
(p7) add r3 = r3,r3
br.call.sptk.few b6 = getbit
;;
(p6) add r3 = r3,r3,1 /* m_len = m_len*2 + getbit()) */
(p7) add r3 = r3,r3
;;
cmp.ne p6,p0 = r0,r3
(p6) br.cond.sptk.few decompr_got_mlen_n2b /* if (m_len == 0) goto decompr_got_mlen_n2b */
add r3 = 1,r3 /* m_len++ */
;;
loop2_n2b:
br.call.sptk.few b6 = getbit
;;
(p6) add r3 = r3,r3,1 /* m_len = m_len*2 + getbit() */
(p7) add r3 = r3,r3
br.call.sptk.few b6 = getbit
;;
(p7) br.cond.sptk.few loop2_n2b /* while(!getbit()) */
add r3 = 2, r3 /* m_len += 2 */
;;
decompr_got_mlen_n2b:
cmp.gtu p6,p7 = r16, r20
;;
(p6) add r3 = 2, r3 /* m_len = m_len + 1 + (last_m_off > 0xd00) */
(p7) add r3 = 1, r3
sub r9 = r15, r16,1 /* m_pos = dst + olen - last_m_off - 1 */
;;
1:
ld1 r19 = [r9],1
add r3 = -1,r3
;;
st1 [r15] = r19,1 /* dst[olen++] = *m_pos++ while(m_len > 0) */
cmp.ne p6,p0 = r0,r3
(p6) br.cond.sptk.few 1b
;;
br.cond.sptk.few decompr_loop_n2b
decompr_end_n2b:
/* Branch to the start address */
mov ar.pfs=r8
;;
mov b6 = r21
;;
br.sptk.few b6
payload:
+28
View File
@@ -0,0 +1,28 @@
OUTPUT_FORMAT("elf64-ia64-little")
OUTPUT_ARCH(ia64)
ENTRY(_start)
SECTIONS {
. = 0;
__gp = .;
_text = . ;
.text : {
*(.text)
}
/DISCARD/ : {
*(.comment)
*(.note)
*(.hash)
*(.data)
*(.sbss)
*(.bss)
*(.dynstr)
*(.dynsym)
*(.IA_64.unwind)
*(.IA_64.unwind_info)
*(.IA64_unwind)
*(.IA64_unwind_info)
*(.dynamic)
}
}