OFW client interface

This commit is contained in:
aramya 2023-07-01 03:52:59 +01:00
parent 8d2f24d9e1
commit aa79432946
6 changed files with 40 additions and 165 deletions

View File

@ -19,8 +19,8 @@ bootinfo.txt: loader/load.fth loader/def.fth
cat loader/load.fth >> bootinfo.txt cat loader/load.fth >> bootinfo.txt
echo "</boot-script></chrp-boot>" >> bootinfo.txt echo "</boot-script></chrp-boot>" >> bootinfo.txt
kernel.elf: start.elf boot.elf kernel.elf: start.elf boot.elf
$(PPC)-ld -Ttext=0x200000 start.elf boot.elf -o kernel.elf $(PPC)-ld -Ttext=0x200000 -Tdata=0x300000 start.elf boot.elf -o kernel.elf
boot.elf: entry/boot.c boot.elf: entry/boot.c entry/boot.h
$(PPC)-gcc -c entry/boot.c -o boot.elf $(PPC)-gcc -c entry/boot.c -o boot.elf
start.elf: entry/start.s start.elf: entry/start.s
$(PPC)-as -c entry/start.s -o start.elf $(PPC)-as -c entry/start.s -o start.elf

View File

@ -1,141 +1,45 @@
#include "boot.h" #include "boot.h"
void __stack_chk_fail_local(void){} 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));
}
else if (IO_TYPE == mac99)
{
screen_width = (*(unsigned int*)(__VRAM__MAC99+4));
screen_height = (*(unsigned int*)(__VRAM__MAC99+8));
}
} }
void init(void) void __eabi(void)
{ {
if (IO_TYPE == beige) }
int test(const char* name)
{
struct
{ {
p_vram = __VRAM__BEIGE; char* service;
p_bios = __BIOS__BEIGE; int n_args;
p_timer= __TIMR__BEIGE; int n_rets;
} char* arg;
else if (IO_TYPE == mac99) int ret;
{ } ofw_arg;
p_vram = __VRAM__MAC99;
p_bios = __BIOS__MAC99; const char _service[5] = "test";
p_timer= __TIMR__MAC99; ofw_arg.service = _service;
}
ofw_arg.n_args = 1;
ofw_arg.n_rets = 1;
ofw_arg.arg = name;
ofw(&ofw_arg);
return ofw_arg.ret;
} }
void main(void) void main(void)
{ {
get_io_type(); asm volatile("stw 5, %0" : "=m"(ofw));
init(); if (test("open"))
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++)
{ {
//24-bit VGA asm("mr 27, 28");
*ptr = a; asm("b $");
ptr++; }
*ptr = b; else
ptr++; {
*ptr = c; asm("mr 30, 31");
ptr++; asm("b $");
*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];
} }
} }

View File

@ -1,26 +1,2 @@
#define beige 0xBE void (*ofw)();
#define mac99 0x5A void __eabi();
#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);

View File

@ -1,5 +1,4 @@
.globl _start .globl _start
.globl ofw
_start: _start:
stwu 1, -0x7fff(1) b main
b main

View File

@ -1,5 +1,4 @@
: initmsg ." powerpc-ofw-boot : Booting through OpenFirmware..." cr ; : initmsg ." powerpc-ofw-boot" cr ;
: startmsg ." Running Game of Life..." cr ;
: sup - dup abs = ; : sup - dup abs = ;
: inf dup sup 1 + ; : inf dup sup 1 + ;
: diff = if 0 else -1 then ; : 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 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-width 4 mac99-vram + l! then
fba mac99-vram = if screen-height 8 mac99-vram + l! then fba mac99-vram = if screen-height 8 mac99-vram + l! then
." informations stored :" cr
fba a dump
variable run variable run
-1 run ! -1 run !
fba beige-vram diff fba mac99-vram diff and if hardware-error 0 run ! then fba beige-vram diff fba mac99-vram diff and if hardware-error 0 run ! then
run @ 0 = if 1 0 do 0 +loop then run @ 0 = if 1 0 do 0 +loop then
startmsg
boot hd:,\boot\kernel.elf boot hd:,\boot\kernel.elf