Page 1 of 1
mac powerpc os development resources
Posted: Mon Jan 12, 2009 2:18 pm
by conekg
Hi All,
I've just bought a second hand Mac Mini G4 and would like to play but figured out that there are not many resources for an OS dev beginner on this architecture.
I would really appreciate if you could post some resources that helped you develop on macppc.
For a start I would especially be interested in:
-Interfacing Mac's display trough Open Firmware
-Interfacing Mac's display without Open Firmware
Thanks,
Nemanja
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 7:47 am
by LMN
Hi,
i've never seen explicit documentation on that. You could try to use the source code of GRUB2, U-Boot, QEMU and Linux as a reference for your coding or even to create some kind of documentation.
Regards
LMN
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 8:47 am
by Colonel Kernel
This book has decent chapters on Open Firmware and PPC architecture & calling conventions.
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 9:46 am
by Troy Martin
Colonel: Dead link.
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 10:01 am
by AJ
Hi,
I tried that link just after Colonel posted it and it was fine. I assume it must be a temporary problem because I can't follow the link now either.
Cheers,
Adam
[Edit: Oh Wait! - it works again!
]
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 11:00 am
by quok
Colonel Kernel wrote:This book has decent chapters on Open Firmware and PPC architecture & calling conventions.
That is simply a great book. It's definitely a must-read for anyone that is interested in developing on the PPC architecture and/or OSX.
You'll also want to do a google search for powerpc assembly, as that'll be needed. Contrary to popular belief, there's some really good information out there, mostly from Apple, IBM, and a couple of decent tutorials.
For Open Firmware, I'd suggest looking at the information available on the OLPC website. Start with this link:
http://wiki.laptop.org/go/Open_Firmware. There's plenty of tutorials on Forth and links to other good references for Open Firmware. Aside from needing to know some Forth to really get a good grasp of Open Firmware, you'll want to look at docs on the client interface.
I'd say forget GRUB-2 and look at BootX. It's covered in the OSX Book, and it's also open source. There's plenty of good docs on BootX as well. On PowerPC, BootX interfaces with OFW and does everything you'll need to get your OS loaded. BootX has been ported to EFI as well for the Intel-based Macs, but that version is not open source, and information is a little bit harder to come by, but is out there.
You may find it easier to follow the instructions at
http://www.openfirmware.info/Open_Firmware if you just want to play with OFW and don't care quite so much about the PPC aspect of things. You can build OFW as a multiboot "kernel" that GRUB can load, as a bootloader in it's own right, or as a direct BIOS/ROM replacement for Qemu/Virtualbox (and probably Bochs, but I haven't tested that one).
Re: mac powerpc os development resources
Posted: Tue Jan 13, 2009 3:31 pm
by conekg
Thanks All !
Mac OS X Internals really looks great. I've given it a quick look on Google Books.
I think I will start with hacking yaboot bootloader that Linux uses. The code does not look too complicated and should get me started with Open Firmware client interface:
http://yaboot.ozlabs.org/
Basically I want to get past depending on open firmware as soon as possible since I am mostly interested in PowerPC part at the moment.
That is why I also asked about display interface without Open Firmware. Something like text memory 0xB8000 in x86?
BR,
Nemanja
Re: mac powerpc os development resources
Posted: Wed Jan 14, 2009 7:56 am
by Colonel Kernel
I think the OS X book is a good reference, but it sure is difficult to read it start-to-finish.
I actually like the pace and style of "Inside Windows NT" (haven't read its newer editions). I think the ideal OS book would have the first 10 chapters as an easy-to-read conceptual introduction, and then all the gory detail in 10 more chapters in the second half.
Amit Singh's writing style leaves much to be desired...
Re: mac powerpc os development resources
Posted: Wed Jan 14, 2009 8:18 am
by JamesM
I managed to port my OS to Mac/PowerPC purely by looking at the manuals and OpenFirmware specifications - I didn't realise that osx book existed!
Basically to answer your question you need to interface with OF to find and look through its device tree. Then you look for the device "screen" - it has an "address" property which is the framebuffer physical address, as well as width, height, depth etc.
Sample code from my OS (It's C++, and you'll have to implement the OpenFirmware wrappers I implemented yourself (or ask me nicely!
)
Code: Select all
void PPCVga::initialise()
{
// Firstly get the screen device.
// TODO: deal more cleanly with failure.
OFDevice screen(OpenFirmware::instance().findDevice("screen"));
// Get the 'chosen' device.
OFDevice chosen(OpenFirmware::instance().findDevice("/chosen"));
// Now we can get the MMU device from chosen.
OFDevice mmu( chosen.getProperty("mmu") );
// Get the (physical) framebuffer address.
OFParam physFbAddr = screen.getProperty("address");
// Create a mapping with OpenFirmware.
/// \todo Something with VirtualAddressSpace here?
mmu.executeMethod("map", 4,
reinterpret_cast<OFParam>(0x6a),
reinterpret_cast<OFParam>(0x01000000),
static_cast<OFParam>(m_pFramebuffer),
physFbAddr); // 0x6a = Uncached.
// Find the device width, height and depth.
m_Width = reinterpret_cast<uint32_t> ( screen.getProperty("width") );
m_Height = reinterpret_cast<uint32_t> ( screen.getProperty("height") );
m_Depth = reinterpret_cast<uint32_t> ( screen.getProperty("depth") );
m_Stride = reinterpret_cast<uint32_t> ( screen.getProperty("linebytes") );
if (m_Depth == 8)
{
for (int i = 0; i < 16; i++)
m_pColours[i] = i;
}
else if (m_Depth == 16)
{
m_pColours[0] = RGB_16 (0x00, 0x00, 0x00); // Black
m_pColours[1] = RGB_16 (0x00, 0x00, 0x99); // Blue
m_pColours[2] = RGB_16 (0x00, 0x99, 0x00); // Green
m_pColours[3] = RGB_16 (0x00, 0x99, 0x99); // Cyan
m_pColours[4] = RGB_16 (0x99, 0x00, 0x00); // Red
m_pColours[5] = RGB_16 (0x99, 0x00, 0x99); // Magenta
m_pColours[6] = RGB_16 (0x99, 0x66, 0x00); // Brown
m_pColours[7] = RGB_16 (0xBB, 0xBB, 0xBB); // Light grey
m_pColours[8] = RGB_16 (0x99, 0x99, 0x99); // Dark grey
m_pColours[9] = RGB_16 (0x00, 0x00, 0xFF); // Light blue
m_pColours[10] =RGB_16 (0x00, 0xFF, 0x00); // Light green
m_pColours[11] =RGB_16 (0x00, 0xFF, 0xFF); // Light cyan
m_pColours[12] =RGB_16 (0xFF, 0x00, 0x00); // Light red
m_pColours[13] =RGB_16 (0xFF, 0x00, 0xFF); // Light magenta
m_pColours[14] =RGB_16 (0xFF, 0xFF, 0x00); // Light brown / yellow
m_pColours[15] =RGB_16 (0xFF, 0xFF, 0xFF); // White
m_Stride /= 2; // 16bpp = 2 bytes per pixel.
}
// Clear the text framebuffer.
uint16_t clear = ' ';
for (unsigned int i = 0; i < (m_Width/FONT_WIDTH)*(m_Height/FONT_HEIGHT); i++)
{
m_pTextBuffer[i] = clear;
}
// Clear the graphics framebuffer.
uint16_t *p16Fb = reinterpret_cast<uint16_t*> (m_pFramebuffer);
uint32_t *p32Fb = reinterpret_cast<uint32_t*> (m_pFramebuffer);
for (unsigned int i = 0; i < m_Stride*m_Height; i++)
{
switch (m_Depth)
{
case 8:
m_pFramebuffer[i] = 0x00;
break;
case 16:
p16Fb[i] = 0x0000;
break;
case 32:
p32Fb[i] = 0x00000000;
break;
}
}
}
EDIT: Note the 0x6a in the call to "map" - This means the memory is mapped as uncacheable, which is
required, else you won't see anything at all!
Re: mac powerpc os development resources
Posted: Wed Jan 14, 2009 12:28 pm
by conekg
Thanks James! I'll try first to work it out myself, if I do not succeed I will ask nicely
BR,
Nemanja