mirror of
https://github.com/thamugadi/powerpc-ofw-boot.git
synced 2024-06-05 14:29:31 +00:00
Compare commits
13 Commits
a7a68be57c
...
75395c1aea
Author | SHA1 | Date | |
---|---|---|---|
|
75395c1aea | ||
|
1a16354d12 | ||
|
9d6a0bbf1d | ||
|
70feb61be3 | ||
|
803d40b487 | ||
|
97f10d22f5 | ||
|
498512fe0d | ||
|
f4deea5298 | ||
|
a987a24e4a | ||
|
511d46db9b | ||
|
07484c2674 | ||
|
80700af624 | ||
|
380d96e70e |
15
Makefile
15
Makefile
|
@ -3,17 +3,17 @@ PPC = powerpc-eabi
|
|||
QEMU = qemu-system-ppc
|
||||
RES = 1600x900x32
|
||||
|
||||
SOURCES_C = $(wildcard entry/*.c)
|
||||
SOURCES_S = $(wildcard entry/*.s)
|
||||
SOURCES_C = $(shell find src -name "*.c")
|
||||
SOURCES_S = $(shell find src -name "*.s")
|
||||
OBJECTS = $(SOURCES_C:.c=.elf) $(SOURCES_S:.s=.elf)
|
||||
|
||||
.PHONY: clean run debug beige
|
||||
|
||||
DISK.APM: kernel.elf bootinfo.txt scripts/kpartx.sh
|
||||
DISK.APM: kernel.elf bootinfo.txt kpartx/kpartx.sh
|
||||
dd bs=512K count=2 if=/dev/zero of=DISK.APM
|
||||
parted DISK.APM --script mklabel mac mkpart primary hfs+ 32.8KB 100%
|
||||
sudo chmod +x scripts/kpartx.sh
|
||||
sudo ./scripts/kpartx.sh
|
||||
sudo chmod +x kpartx/kpartx.sh
|
||||
sudo ./kpartx/kpartx.sh
|
||||
sudo mkdir -p /mnt/ppc /mnt/boot
|
||||
sudo cp bootinfo.txt /mnt/ppc
|
||||
sudo cp kernel.elf /mnt/boot
|
||||
|
@ -27,7 +27,7 @@ bootinfo.txt: loader/load.fth loader/def.fth
|
|||
echo "</boot-script></chrp-boot>" >> bootinfo.txt
|
||||
|
||||
kernel.elf: $(OBJECTS)
|
||||
$(PPC)-ld -Ttext=0x200000 -Tdata=0x300100 $^ -o $@
|
||||
$(PPC)-ld -Ttext=0x02000000 -Tdata=0x02100000 $^ -o $@
|
||||
|
||||
%.elf: %.c
|
||||
$(PPC)-gcc -I include -c $< -o $@
|
||||
|
@ -36,7 +36,8 @@ kernel.elf: $(OBJECTS)
|
|||
$(PPC)-as -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.APM *elf *txt
|
||||
rm -f *.APM *txt
|
||||
find src -name "*.elf" -type f -delete
|
||||
|
||||
run:
|
||||
$(QEMU) -hda *.APM -g $(RES) -machine $(MACHINE)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <ofw.h>
|
||||
|
||||
void (*ofw)();
|
||||
void __eabi();
|
||||
|
||||
|
@ -10,7 +12,9 @@ void __eabi(void)
|
|||
|
||||
void main(void)
|
||||
{
|
||||
if (ofw_test("open"))
|
||||
while(1)
|
||||
interpret("blink-screen", 0, 0, 0, 0);
|
||||
if (test("open"))
|
||||
{
|
||||
asm("mr 27, 28");
|
||||
asm("b $");
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
extern void (*ofw)();
|
||||
|
||||
int ofw_test(char* name)
|
||||
int32_t test(char* name)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg;
|
||||
int ret;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("test", 5, 1, 1);
|
73
src/ofw/control.c
Normal file
73
src/ofw/control.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
void boot(char* bootspec)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("boot", 5, 1, 0);
|
||||
|
||||
ofw_arg.arg = bootspec;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
||||
void enter(void)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("enter", 6, 0, 0);
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
||||
void ofw_exit(void)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("exit", 5, 0, 0);
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
||||
void chain(void* virt, int32_t size, void* entry, void* args, int32_t len)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
void* arg1;
|
||||
int32_t arg2;
|
||||
void* arg3;
|
||||
void* arg4;
|
||||
int32_t arg5;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("chain", 6, 5, 0);
|
||||
|
||||
ofw_arg.arg1 = virt;
|
||||
ofw_arg.arg2 = size;
|
||||
ofw_arg.arg3 = entry;
|
||||
ofw_arg.arg4 = args;
|
||||
ofw_arg.arg5 = len;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
77
src/ofw/interface.c
Normal file
77
src/ofw/interface.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
void* interpret(char* cmd, int32_t* stack_args, int n_stack_args, int n_ret_args, int32_t* retaddr)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg1;
|
||||
int32_t argN[n_stack_args];
|
||||
int32_t ret1;
|
||||
int32_t retN[n_ret_args];
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("interpret", 10, 1+n_stack_args, n_ret_args);
|
||||
|
||||
ofw_arg.arg1 = cmd;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < n_stack_args; i++)
|
||||
{
|
||||
ofw_arg.argN[i] = stack_args[i];
|
||||
}
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
*retaddr = ofw_arg.ret1;
|
||||
for (i = 1; i < n_ret_args+1; i++)
|
||||
{
|
||||
retaddr[i] = ofw_arg.retN[i];
|
||||
}
|
||||
|
||||
return retaddr;
|
||||
}
|
||||
|
||||
void* set_callback(void* addr)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
void* arg;
|
||||
void* ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("set-callback", 13, 1, 1);
|
||||
|
||||
ofw_arg.arg = addr;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
void set_symbol_lookup(void* sym_to_value, void* value_to_sym)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
void* arg1;
|
||||
void* arg2;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("set-symbol-lookup", 17, 2, 0);
|
||||
|
||||
ofw_arg.arg1 = sym_to_value;
|
||||
ofw_arg.arg2 = value_to_sym;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
||||
|
113
src/ofw/io.c
Normal file
113
src/ofw/io.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
ihandle open(char* device_specifier)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg;
|
||||
ihandle ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("open", 5, 1, 1);
|
||||
|
||||
ofw_arg.arg = device_specifier;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
void close(ihandle instance)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("close", 6, 1, 0);
|
||||
|
||||
ofw_arg.arg = instance;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
||||
int32_t read(ihandle instance, void* addr, int32_t len)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg1;
|
||||
void* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("read", 5, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = instance;
|
||||
ofw_arg.arg2 = addr;
|
||||
ofw_arg.arg3 = len;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int32_t write(ihandle instance, void* addr, int32_t len)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg1;
|
||||
void* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("write", 6, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = instance;
|
||||
ofw_arg.arg2 = addr;
|
||||
ofw_arg.arg3 = len;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
return ofw_arg.ret;
|
||||
|
||||
}
|
||||
|
||||
int32_t seek(ihandle instance, int32_t pos_hi, int32_t pos_lo)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg1;
|
||||
int32_t* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("seek", 5, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = instance;
|
||||
ofw_arg.arg2 = pos_hi;
|
||||
ofw_arg.arg3 = pos_lo;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
return ofw_arg.ret;
|
||||
|
||||
}
|
47
src/ofw/mem.c
Normal file
47
src/ofw/mem.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
void* claim(void* virt, int32_t size, int32_t align)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
void* arg1;
|
||||
int32_t arg2;
|
||||
int32_t arg3;
|
||||
void* ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("claim", 6, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = virt;
|
||||
ofw_arg.arg2 = size;
|
||||
ofw_arg.arg3 = align;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
|
||||
void release(void* virt, int32_t size)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
void* arg1;
|
||||
int32_t arg2;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("release", 8, 2, 0);
|
||||
|
||||
ofw_arg.arg1 = virt;
|
||||
ofw_arg.arg2 = size;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
}
|
||||
|
20
src/ofw/time.c
Normal file
20
src/ofw/time.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
int32_t milliseconds(void)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("milliseconds", 13, 0, 1);
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
return ofw_arg.ret;
|
||||
}
|
|
@ -7,8 +7,8 @@ phandle child(phandle _child)
|
|||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
@ -26,8 +26,8 @@ phandle parent(phandle _parent)
|
|||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
@ -45,8 +45,8 @@ phandle instance_to_package(ihandle instance)
|
|||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
@ -59,16 +59,16 @@ phandle instance_to_package(ihandle instance)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int getproplen(phandle node, char* name)
|
||||
int32_t getproplen(phandle node, char* name)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
int ret;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("getproplen", 11, 2, 1);
|
||||
|
@ -80,18 +80,18 @@ int getproplen(phandle node, char* name)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int getprop(phandle node, char* name, uint8_t* buf, int buflen)
|
||||
int32_t getprop(phandle node, char* name, void* buf, int32_t buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int arg4;
|
||||
int ret;
|
||||
void* arg3;
|
||||
int32_t arg4;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("getprop", 8, 4, 1);
|
||||
|
@ -105,17 +105,17 @@ int getprop(phandle node, char* name, uint8_t* buf, int buflen)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int nextprop(phandle node, char* previous, uint8_t* buf)
|
||||
int32_t nextprop(phandle node, char* previous, void* buf)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int ret;
|
||||
void* arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("nextprop", 9, 3, 1);
|
||||
|
@ -128,18 +128,18 @@ int nextprop(phandle node, char* previous, uint8_t* buf)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int setprop(phandle node, char* name, uint8_t* buf, int len)
|
||||
int32_t setprop(phandle node, char* name, void* buf, int32_t len)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int arg4;
|
||||
int ret;
|
||||
void* arg3;
|
||||
int32_t arg4;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
char _service[8] = "setprop";
|
||||
|
@ -156,17 +156,17 @@ int setprop(phandle node, char* name, uint8_t* buf, int len)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int canon(char* device, uint8_t* buf, int buflen)
|
||||
int32_t canon(char* device, void* buf, int32_t buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
void* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("canon", 6, 3, 1);
|
||||
|
@ -184,10 +184,10 @@ phandle finddevice(char* device)
|
|||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg1;
|
||||
int ret;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("finddevice", 11, 1, 1);
|
||||
|
@ -198,17 +198,17 @@ phandle finddevice(char* device)
|
|||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int instance_to_path(ihandle instance, uint8_t* buf, int buflen)
|
||||
int32_t instance_to_path(ihandle instance, void* buf, int32_t buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
void* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("instance-to-path", 17, 3, 1);
|
||||
|
@ -222,17 +222,17 @@ int instance_to_path(ihandle instance, uint8_t* buf, int buflen)
|
|||
|
||||
}
|
||||
|
||||
int package_to_path(phandle package, uint8_t* buf, int buflen)
|
||||
int32_t package_to_path(phandle package, void* buf, int32_t buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
ihandle arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
void* arg2;
|
||||
int32_t arg3;
|
||||
int32_t ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("package-to-path", 16, 3, 1);
|
||||
|
@ -246,7 +246,39 @@ int package_to_path(phandle package, uint8_t* buf, int buflen)
|
|||
|
||||
}
|
||||
|
||||
void* call_method(char* method, ihandle instance, ...)
|
||||
void* call_method(char* method, ihandle instance, int32_t* stack_args, int32_t n_stack_args, int32_t n_ret_args, int32_t* retaddr)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int32_t n_args;
|
||||
int32_t n_rets;
|
||||
char* arg1;
|
||||
ihandle arg2;
|
||||
int32_t argN[n_stack_args];
|
||||
int32_t ret1;
|
||||
int32_t retN[n_ret_args];
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("call-method", 12, 2+n_stack_args, n_ret_args);
|
||||
|
||||
ofw_arg.arg1 = method;
|
||||
ofw_arg.arg2 = instance;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < n_stack_args; i++)
|
||||
{
|
||||
ofw_arg.argN[i] = stack_args[i];
|
||||
}
|
||||
|
||||
ofw(&ofw_arg);
|
||||
|
||||
*retaddr = ofw_arg.ret1;
|
||||
for (i = 1; i < n_ret_args+1; i++)
|
||||
{
|
||||
retaddr[i] = ofw_arg.retN[i];
|
||||
}
|
||||
|
||||
return retaddr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user