shithub: p9-stm32-example-os

ref: f801657f77f3923ec2388c25bdcb036c8019ba89
dir: /main.c/

View raw version
#include	<u.h>
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"libkern/kern.h"
#include	"debug.h"

#include	"prog/prog.h"

Conf conf;
Mach *m = (Mach*)MACHADDR;
Proc *up = 0;
int apsr_flags = 0;

void
main()
{
	/*	hardware bootstrap	*/
	memset(m, 0, sizeof(Mach));
	memset(edata, 0, end-edata);

	/* initialize system */
	trapinit();
	clockinit();
	allocinit();
	dmainit();

	/* initialize peripherals and enable the DMA */
	gpioinit();
	afioinit();
	uartinit();

	dmaenable();

	/*	entrypoint	*/
	gpio_toggle_n(3);
	print("\n  /\\__/\\\n");
	print(" (  ^ ^ )\n");
	print("  `----`\n");
	print("system booting					kitzman unlimited © 2023\n");
	for(int i = 0; i < 3; i++) {
		print("%d...", 3 - i);
		gpio_toggle_n(3);
	}
	print("\n");

	print("boot: edata 0x%08x end 0x%08x\n", edata, end);

	/*	operating system init	*/
	DBGSTART print("boot: confinit...\n");		confinit();
	DBGSTART print("boot: timersinit...\n");	timersinit();
	DBGSTART print("boot: systick starting\n");	systickinit();

	DBGSTART print("boot: procinit...\n");		procinit();
	DBGSTART print("boot: userinit...\n");		userinit();
	DBGSTART print("boot: scheduling\n");		schedinit(); while(1);
}

void
idlehands()
{
}

void
halt()
{
	print("system halted; you can now disconnect your devices\n");
	while(1) gpio_toggle_n(6);
}

void
reboot()
{
	print("reboot function not yet implemented\n");
	while(1) gpio_toggle_n(3);
}

void
confinit()
{
	conf.topofmem = DATAEADDR;
	conf.ialloc = BY2PG;
	conf.nproc = 8;
	conf.nmach = 1;

	active.machs = 1;
	active.exiting = 0;
}

void
userinit()
{
	Proc *p = prog_init0();
	ready(p);
}