mirror of
https://github.com/thamugadi/powerpc-ofw-boot.git
synced 2024-09-26 17:55:37 +00:00
Compare commits
No commits in common. "a7a68be57c0a31a78f0f8337bad632ebd8abbe3b" and "8d2f24d9e18241ffa4d0f10062f5321819460764" have entirely different histories.
a7a68be57c
...
8d2f24d9e1
44
Makefile
44
Makefile
@ -1,45 +1,37 @@
|
||||
MACHINE = mac99
|
||||
PPC = powerpc-eabi
|
||||
QEMU = qemu-system-ppc
|
||||
RES = 1600x900x32
|
||||
|
||||
SOURCES_C = $(wildcard entry/*.c)
|
||||
SOURCES_S = $(wildcard entry/*.s)
|
||||
OBJECTS = $(SOURCES_C:.c=.elf) $(SOURCES_S:.s=.elf)
|
||||
|
||||
.PHONY: clean run debug beige
|
||||
|
||||
MACHINE=mac99
|
||||
PPC=powerpc-eabi
|
||||
QEMU=qemu-system-ppc
|
||||
RES=1600x900x32
|
||||
DISK.APM: kernel.elf bootinfo.txt scripts/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 mkdir -p /mnt/ppc /mnt/boot
|
||||
sudo mkdir /mnt/ppc
|
||||
sudo mkdir /mnt/boot
|
||||
sudo cp bootinfo.txt /mnt/ppc
|
||||
sudo cp kernel.elf /mnt/boot
|
||||
sudo umount /mnt/
|
||||
sudo kpartx -d DISK.APM
|
||||
|
||||
bootinfo.txt: loader/load.fth loader/def.fth
|
||||
echo "<chrp-boot><boot-script>" >> bootinfo.txt
|
||||
cat loader/def.fth >> bootinfo.txt
|
||||
cat loader/load.fth >> bootinfo.txt
|
||||
echo "</boot-script></chrp-boot>" >> bootinfo.txt
|
||||
|
||||
kernel.elf: $(OBJECTS)
|
||||
$(PPC)-ld -Ttext=0x200000 -Tdata=0x300100 $^ -o $@
|
||||
|
||||
%.elf: %.c
|
||||
$(PPC)-gcc -I include -c $< -o $@
|
||||
|
||||
%.elf: %.s
|
||||
$(PPC)-as -c $< -o $@
|
||||
|
||||
kernel.elf: start.elf boot.elf
|
||||
$(PPC)-ld -Ttext=0x200000 start.elf boot.elf -o kernel.elf
|
||||
boot.elf: entry/boot.c
|
||||
$(PPC)-gcc -c entry/boot.c -o boot.elf
|
||||
start.elf: entry/start.s
|
||||
$(PPC)-as -c entry/start.s -o start.elf
|
||||
clean:
|
||||
rm -f *.APM *elf *txt
|
||||
|
||||
rm *.APM *elf *txt
|
||||
run:
|
||||
$(QEMU) -hda *.APM -g $(RES) -machine $(MACHINE)
|
||||
$(QEMU) -hda *.APM -g $(RES) -machine $(MACHINE)
|
||||
beige:
|
||||
$(QEMU) -hda *.APM -g $(RES) -machine g3beige
|
||||
|
||||
debug:
|
||||
$(QEMU) -hda *.APM -d in_asm -g $(RES) -machine $(MACHINE)
|
||||
all:
|
||||
make clean && make && make run
|
||||
|
144
entry/boot.c
144
entry/boot.c
@ -1,23 +1,141 @@
|
||||
void (*ofw)();
|
||||
void __eabi();
|
||||
#include "boot.h"
|
||||
void __stack_chk_fail_local(void){}
|
||||
void __eabi(void){}
|
||||
void get_io_type(void)
|
||||
{
|
||||
if (*(unsigned char*)__VRAM__BEIGE == beige) IO_TYPE = beige;
|
||||
else if (*(unsigned char*)__VRAM__MAC99 == mac99) IO_TYPE = mac99;
|
||||
if (IO_TYPE == beige)
|
||||
{
|
||||
screen_width = (*(unsigned int*)(__VRAM__BEIGE+4));
|
||||
screen_height = (*(unsigned int*)(__VRAM__BEIGE+8));
|
||||
|
||||
void __stack_chk_fail_local(void)
|
||||
{
|
||||
}
|
||||
else if (IO_TYPE == mac99)
|
||||
{
|
||||
screen_width = (*(unsigned int*)(__VRAM__MAC99+4));
|
||||
screen_height = (*(unsigned int*)(__VRAM__MAC99+8));
|
||||
}
|
||||
}
|
||||
void __eabi(void)
|
||||
void init(void)
|
||||
{
|
||||
if (IO_TYPE == beige)
|
||||
{
|
||||
p_vram = __VRAM__BEIGE;
|
||||
p_bios = __BIOS__BEIGE;
|
||||
p_timer= __TIMR__BEIGE;
|
||||
}
|
||||
else if (IO_TYPE == mac99)
|
||||
{
|
||||
p_vram = __VRAM__MAC99;
|
||||
p_bios = __BIOS__MAC99;
|
||||
p_timer= __TIMR__MAC99;
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
if (ofw_test("open"))
|
||||
get_io_type();
|
||||
init();
|
||||
game_of_life();
|
||||
}
|
||||
|
||||
void fillscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n)
|
||||
{
|
||||
unsigned char* ptr = addr;
|
||||
for (unsigned int i = 0; i<n; i++)
|
||||
{
|
||||
asm("mr 27, 28");
|
||||
asm("b $");
|
||||
}
|
||||
else
|
||||
{
|
||||
asm("mr 30, 31");
|
||||
asm("b $");
|
||||
//24-bit VGA
|
||||
*ptr = a;
|
||||
ptr++;
|
||||
*ptr = b;
|
||||
ptr++;
|
||||
*ptr = c;
|
||||
ptr++;
|
||||
*ptr = 0;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
void memcpy(unsigned char* dest, unsigned char* src, int n)
|
||||
{
|
||||
unsigned char* destination = dest;
|
||||
unsigned char* source = src;
|
||||
for (int i = 0; i<n; i++)
|
||||
{
|
||||
*destination = *source;
|
||||
destination++; source++;
|
||||
}
|
||||
}
|
||||
|
||||
void game_of_life(void)
|
||||
{
|
||||
int N = screen_width;
|
||||
int i,j,ip1,jp1,nei;
|
||||
unsigned int random;
|
||||
unsigned char universe[N][N];
|
||||
unsigned char universe2[N][N];
|
||||
unsigned char* junk_beige = 0x81040000;
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
if (IO_TYPE == mac99)
|
||||
{
|
||||
random = (*p_timer + *p_bios);
|
||||
if (!(random%7)) universe[i][j] = 1;
|
||||
else universe[i][j] = 0;
|
||||
p_bios++;
|
||||
}
|
||||
else if (IO_TYPE == beige)
|
||||
{
|
||||
random = (*junk_beige);
|
||||
if (!(random%3)) universe[i][j] = 1;
|
||||
else universe[i][j] = 0;
|
||||
junk_beige++;
|
||||
}
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
init();
|
||||
memcpy(p_vram, p_vram+255, 400000);
|
||||
|
||||
p_vram += 400000;
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
if (universe[i][j]) fillscreen(p_vram, 255,255,255,1);
|
||||
else fillscreen(p_vram,200 ,210,5,1);
|
||||
p_vram+=4;
|
||||
}
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++) universe2[i][j] = universe[i][j];
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
nei = 0;
|
||||
ip1 = i + 1;
|
||||
jp1 = j + 1;
|
||||
if (i == N) ip1=0;
|
||||
if (j == N) jp1=0;
|
||||
if (!i) ip1=N;
|
||||
if (!j) jp1=N;
|
||||
if (universe[i][jp1]) nei++;
|
||||
if (universe[ip1][j]) nei++;
|
||||
if (universe[i][j-1]) nei++;
|
||||
if (universe[i-1][j]) nei++;
|
||||
if (universe[ip1][jp1]) nei++;
|
||||
if (universe[ip1][j-1]) nei++;
|
||||
if (universe[i-1][jp1]) nei++;
|
||||
if (universe[i-1][j-1]) nei++;
|
||||
|
||||
if (universe[i][j])
|
||||
{
|
||||
if (nei == 2 || nei == 3) universe2[i][j] = universe[i][j];
|
||||
else universe2[i][j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nei == 3) universe2[i][j] = 1;
|
||||
else universe2[i][j] = universe[i][j];
|
||||
}
|
||||
|
||||
}
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++) universe[i][j] = universe2[i][j];
|
||||
}
|
||||
}
|
||||
|
26
entry/boot.h
Normal file
26
entry/boot.h
Normal file
@ -0,0 +1,26 @@
|
||||
#define beige 0xBE
|
||||
#define mac99 0x5A
|
||||
|
||||
#define __VRAM__BEIGE 0x80000000
|
||||
#define __BIOS__BEIGE 0xFFC00000
|
||||
#define __TIMR__BEIGE 0 //
|
||||
#define __VRAM__MAC99 0x81000000
|
||||
#define __BIOS__MAC99 0xFFF00000
|
||||
#define __TIMR__MAC99 0x80080038
|
||||
void __stack_chk_fail_local();
|
||||
|
||||
unsigned char IO_TYPE;
|
||||
unsigned int screen_width;
|
||||
unsigned int screen_height;
|
||||
|
||||
unsigned char* p_vram;
|
||||
unsigned char* p_bios;
|
||||
unsigned char* p_timer;
|
||||
unsigned char u8_extract_bit(unsigned char n, unsigned char bit);
|
||||
void get_io_type(void);
|
||||
void init(void);
|
||||
void fillscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n);
|
||||
void memcpy(unsigned char* dest, unsigned char* src, int n);
|
||||
unsigned char u8_extract_bit(unsigned char n, unsigned char bit);
|
||||
unsigned char u32_extract_bit(unsigned int n, unsigned char bit);
|
||||
|
@ -1,252 +0,0 @@
|
||||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
phandle child(phandle _child)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("child", 6, 1, 1);
|
||||
|
||||
ofw_arg.arg = _child;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
phandle parent(phandle _parent)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("parent", 7, 1, 1);
|
||||
|
||||
ofw_arg.arg = _parent;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
phandle instance_to_package(ihandle instance)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
ihandle arg;
|
||||
phandle ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("instance-to-package", 20, 1, 1);
|
||||
|
||||
ofw_arg.arg = instance;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int getproplen(phandle node, char* name)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("getproplen", 11, 2, 1);
|
||||
|
||||
ofw_arg.arg1 = node;
|
||||
ofw_arg.arg2 = name;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int getprop(phandle node, char* name, uint8_t* buf, int buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int arg4;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("getprop", 8, 4, 1);
|
||||
|
||||
ofw_arg.arg1 = node;
|
||||
ofw_arg.arg2 = name;
|
||||
ofw_arg.arg3 = buf;
|
||||
ofw_arg.arg4 = buflen;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int nextprop(phandle node, char* previous, uint8_t* buf)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("nextprop", 9, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = node;
|
||||
ofw_arg.arg2 = previous;
|
||||
ofw_arg.arg3 = buf;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int setprop(phandle node, char* name, uint8_t* buf, int len)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
phandle arg1;
|
||||
char* arg2;
|
||||
uint8_t* arg3;
|
||||
int arg4;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
char _service[8] = "setprop";
|
||||
ofw_arg.service = _service;
|
||||
|
||||
ofw_arg.n_args = 4;
|
||||
ofw_arg.n_rets = 1;
|
||||
ofw_arg.arg1 = node;
|
||||
ofw_arg.arg2 = name;
|
||||
ofw_arg.arg3 = buf;
|
||||
ofw_arg.arg4 = len;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int canon(char* device, uint8_t* buf, int buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
char* arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("canon", 6, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = device;
|
||||
ofw_arg.arg2 = buf;
|
||||
ofw_arg.arg3 = buflen;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
phandle finddevice(char* device)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
char* arg1;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("finddevice", 11, 1, 1);
|
||||
|
||||
ofw_arg.arg1 = device;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
||||
int instance_to_path(ihandle instance, uint8_t* buf, int buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
ihandle arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("instance-to-path", 17, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = instance;
|
||||
ofw_arg.arg2 = buf;
|
||||
ofw_arg.arg3 = buflen;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
|
||||
}
|
||||
|
||||
int package_to_path(phandle package, uint8_t* buf, int buflen)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
ihandle arg1;
|
||||
uint8_t* arg2;
|
||||
int arg3;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("package-to-path", 16, 3, 1);
|
||||
|
||||
ofw_arg.arg1 = package;
|
||||
ofw_arg.arg2 = buf;
|
||||
ofw_arg.arg3 = buflen;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
|
||||
}
|
||||
|
||||
void* call_method(char* method, ihandle instance, ...)
|
||||
{
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include <ofw.h>
|
||||
|
||||
extern void (*ofw)();
|
||||
|
||||
int ofw_test(char* name)
|
||||
{
|
||||
struct
|
||||
{
|
||||
char* service;
|
||||
int n_args;
|
||||
int n_rets;
|
||||
char* arg;
|
||||
int ret;
|
||||
} ofw_arg;
|
||||
|
||||
SERVICE("test", 5, 1, 1);
|
||||
|
||||
ofw_arg.arg = name;
|
||||
|
||||
ofw(&ofw_arg);
|
||||
return ofw_arg.ret;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
.globl _start
|
||||
.extern ofw
|
||||
_start:
|
||||
lis 9, ofw@ha
|
||||
ori 9, 9, ofw@l
|
||||
stw 5, 0(9)
|
||||
b main
|
||||
stwu 1, -0x7fff(1)
|
||||
|
||||
b main
|
||||
|
@ -1,10 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define SERVICE(name, len, args, rets) \
|
||||
char _service[len] = name; \
|
||||
ofw_arg.service = _service; \
|
||||
ofw_arg.n_args = args; \
|
||||
ofw_arg.n_rets = rets;
|
||||
|
||||
typedef int phandle;
|
||||
typedef int ihandle;
|
@ -1,4 +1,5 @@
|
||||
: initmsg ." powerpc-ofw-boot" cr ;
|
||||
: initmsg ." powerpc-ofw-boot : Booting through OpenFirmware..." cr ;
|
||||
: startmsg ." Running Game of Life..." cr ;
|
||||
: sup - dup abs = ;
|
||||
: inf dup sup 1 + ;
|
||||
: diff = if 0 else -1 then ;
|
||||
|
@ -5,8 +5,11 @@ fba beige-vram = if screen-width 4 beige-vram + l! then
|
||||
fba beige-vram = if screen-height 8 beige-vram + l! then
|
||||
fba mac99-vram = if screen-width 4 mac99-vram + l! then
|
||||
fba mac99-vram = if screen-height 8 mac99-vram + l! then
|
||||
." informations stored :" cr
|
||||
fba a dump
|
||||
variable run
|
||||
-1 run !
|
||||
fba beige-vram diff fba mac99-vram diff and if hardware-error 0 run ! then
|
||||
run @ 0 = if 1 0 do 0 +loop then
|
||||
startmsg
|
||||
boot hd:,\boot\kernel.elf
|
||||
|
Loading…
Reference in New Issue
Block a user