Compare commits

...

8 Commits

Author SHA1 Message Date
aramya a7a68be57c cleaning 2023-07-01 12:35:19 +01:00
aramya cf626c7eab SERVICE macro 2023-07-01 12:23:50 +01:00
aramya 7005a2c281 separated files 2023-07-01 12:08:55 +01:00
aramya 3c40f50fb6 device tree methods 2023-07-01 12:07:36 +01:00
aramya 3de2240706 loading ofw address 2023-07-01 11:27:07 +01:00
aramya 75d8667cb3 makefile 2023-07-01 10:43:35 +01:00
aramya 74790b7525 ofw_test 2023-07-01 04:34:00 +01:00
aramya aa79432946 OFW client interface 2023-07-01 03:52:59 +01:00
9 changed files with 331 additions and 184 deletions

View File

@ -1,37 +1,45 @@
MACHINE=mac99
PPC=powerpc-eabi
QEMU=qemu-system-ppc
RES=1600x900x32
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
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 /mnt/ppc
sudo mkdir /mnt/boot
sudo mkdir -p /mnt/ppc /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: 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
kernel.elf: $(OBJECTS)
$(PPC)-ld -Ttext=0x200000 -Tdata=0x300100 $^ -o $@
%.elf: %.c
$(PPC)-gcc -I include -c $< -o $@
%.elf: %.s
$(PPC)-as -c $< -o $@
clean:
rm *.APM *elf *txt
rm -f *.APM *elf *txt
run:
$(QEMU) -hda *.APM -g $(RES) -machine $(MACHINE)
beige:
$(QEMU) -hda *.APM -g $(RES) -machine g3beige
$(QEMU) -hda *.APM -g $(RES) -machine $(MACHINE)
debug:
$(QEMU) -hda *.APM -d in_asm -g $(RES) -machine $(MACHINE)
all:
make clean && make && make run

View File

@ -1,141 +1,23 @@
#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 (*ofw)();
void __eabi();
}
else if (IO_TYPE == mac99)
{
screen_width = (*(unsigned int*)(__VRAM__MAC99+4));
screen_height = (*(unsigned int*)(__VRAM__MAC99+8));
}
}
void init(void)
void __stack_chk_fail_local(void)
{
}
void __eabi(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)
{
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++)
if (ofw_test("open"))
{
//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];
asm("mr 27, 28");
asm("b $");
}
else
{
asm("mr 30, 31");
asm("b $");
}
}

View File

@ -1,26 +0,0 @@
#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);

252
entry/devicetree.c Normal file
View File

@ -0,0 +1,252 @@
#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, ...)
{
}

23
entry/ofw_common.c Normal file
View File

@ -0,0 +1,23 @@
#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;
}

View File

@ -1,5 +1,7 @@
.globl _start
.extern ofw
_start:
stwu 1, -0x7fff(1)
b main
lis 9, ofw@ha
ori 9, 9, ofw@l
stw 5, 0(9)
b main

10
include/ofw.h Normal file
View File

@ -0,0 +1,10 @@
#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;

View File

@ -1,5 +1,4 @@
: initmsg ." powerpc-ofw-boot : Booting through OpenFirmware..." cr ;
: startmsg ." Running Game of Life..." cr ;
: initmsg ." powerpc-ofw-boot" cr ;
: sup - dup abs = ;
: inf dup sup 1 + ;
: diff = if 0 else -1 then ;

View File

@ -5,11 +5,8 @@ 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