Are there some references left for the Mac OS Classic runtime? - retro-computing

I'm working on an implementation of the Mac OS Classic runtime to run Classic programs on OS X again. The project includes a PowerPC emulator, a PEF executable linker, and the possibility to call into native (x86) code.
The emulator and the linker seem to work well, so I've shifted my focus towards (re)implementing Mac OS Classic libraries. I am currently trying to run MPW tools with my "emulator"; grabbing a copy of the MPW Shell literally just hours before Apple pulled it from its servers and running it inside SheepShaver, I compiled your generic "Hello World!" program and I am able to run it successfully.
However, that's about as far as compatibility goes. As I tried to run the Unmangle program, I found that it is trying to access _IntEnv and __NubAt3, two StdCLib exported globals, for which there apparently remains no documentation. (Google still has some Apple mailing list results for linkage problems in the early days of Mac OS X; Bing and Yahoo! turn back no result.)
I find that lack of documentation particularly upsetting. I am sometimes able to guess the globals' layout with Classic header files or even how they're used in programs with the disassembly, but it's not really efficient and there's nothing to tell me I got it right.
And even if I get most of StdCLib right, I'll still need documentation about other libraries at some point.
Where can I find documentation about the Mac OS Classic runtime?

You may still be able to find some relevant Inside Macintosh volumes among what remains of Apple's classic Mac developer documentation.

Related

Can you code a shell for Linux using Windows OS and Dev-C++ IDE? Do shells work the same way for both operating systems?

I'm studying computer engineering and we have a class called operating systems where they lecture us about how OSes handle stuff etc. This week we were given a homework which requests us to code a shell that works on Linux. The problem is, they tought us literally nothing on how to code a shell so we are supposed to do some research and figure it out.
I found this guide online and it seemed perfect to me: link
Code, with explanations, what else could I ask for.
Now, I'm using a Windows PC and I use Dev-C++ IDE with GCC compiler. Can I code a shell that works on Linux with my current setup or do I have to install Linux? Are there any major differences between how shells run on these OSes?
If you want to write a shell for Linux, you want to target GNU/Linux which is basically POSIX with some extensions.
Dev-C++ by default uses MinGW GCC as its compiler, providing a Win32 API.
Win32 and POSIX are completely and fundamentally different. A shell written for one will not even slightly resemble the other.
Instead, you have several options:
Dev-C++ can optionally use Cygwin GCC, providing a more GNU/Linux-like experience on Windows. You need to take great care not to rely on any Cygwin-specific functionality like how it automatically translates pathnames and line terminators. You'll still need access to a Linux install to verify that it works.
Windows 10 lets you install WSL, a more modern Linux compatibility layer for Windows. Dev-C++ doesn't explicitly states it support it, so you may need to edit and compile separately, and may lose debugging functionality. You'll still need access to a Linux install to verify that it works.
Just run Linux in a VM. The only thing to care about is getting your shell working.
I would suggest saving yourself a ton of trouble right now and just download/install an Ubuntu image in VirtualBox.

"windows.h" Not Found Using Eclipse SPARC bare-C Compiler

OK, so I am trying to connect an emulated (Through TSIM) LEON3 processor to a UART terminal. If I am not mistaken I believe I need to compile a C program to enable it to talk with a terminal as I am having difficulties doing it another way.
I found some source code for UART communication here and it all seems to be OK.
However, I am having issues compiling it using the SPARC Bare C Toolchain in Eclipse as it is saying that the windows.h file does not exist. Now I know it exists as I've compiled it successfully using the GCC Toolchain and can't find any similar cases on the web as to why this would be happening.
Is there anyone out there who has had a similar problem or knows the solution?
Additionally, if you know me to be doing the wrong thing in regards to the LEON3 UART comms, please let me know and I will just leave.
Thanks.
BCC is a cross compiler targeting standalone, LEON3- and LEON4-based environments. As a cross compiler, its job is to build binaries for a different environment than the one in which it runs.
Relevant header files describe functions available to a program in its runtime (target) environment. Build-environment libraries and their headers are irrelevant when cross compiling because the build and target environments differ. BCC is correct to expose only the headers for the environment for which it compiles, and that environment does not provide Windows API functions. If the code you're trying to build depends on the Windows API, then you'll need to modify it to remove that dependency, or else find something different.
On the other hand, I strongly suspect that you're going about this whole thing the wrong way. In particular, when you say,
I believe I need to compile a C program to enable it to talk with a terminal
it sounds like you think you're going to build some kind of helper program, but if that's your idea then either you're building it for the wrong environment or you have the wrong idea altogether.
If you want a Windows program that talks to the emulated machine, then you should be building that as a Windows program, and BCC doesn't do that. In that case, you should be using MinGW's gcc, or another C compiler for the emulator's host environment. Moreover, the host-side interface to the emulated environment's UART is an aspect of the emulator. I haven't a clue what emulator you're using, but it might not present the host (Windows) side of that interface as a UART, and it might not require using the Windows API at all.
Or if you indeed do intend to build a program for the standalone LEON3 target environment, then you need to understand that when it runs, it will be the only program that will be running in that environment. That's what "standalone" means -- no OS underneath, therefore no separate processes, and often not even multiple threads of execution. Thus, you do not need a helper program; you just need a program.
The BCC documentation talks about the libraries available there, and in particular, it describes how in that environment, file I/O is allowed only on the standard input and output streams, which are mapped to UART A. Thus, if you use BCC to build the program to run in the emulator, then you don't need to do anything special on that end to talk to the UART. You just use stdio functions directed at stdin and stdout.
On the third hand, if you are running an actual operating system in your emulated environment, then to build programs that run on it you should be using either a native compiler for that environment, in that environment, or else a cross compiler targeting that hosted environment. Either way, BCC is not such a compiler, but GCC might be. Anyway, since Windows does not run on LEON3, it's safe to say that if this is what you're trying to do then you still need something that does not depend on the Windows API.

The Linux kernels 3.* series won't boot properly upon being customly compiled in Ubuntu 16.04.1 by means of make-kpkg and gcc-4.8.5

Recently I upgraded up to Ubuntu 16.04.1 Xenial (from 14.04 Trusty) the build-host where I've compiled different linux kernels so far for my own project. Ubuntu 16.04.1 implies using a new updated environment for building binaries. These tools include a new gcc-5.4, libc6 (for userspace applications), etc. Also a new Ubuntu supplies (or suggests) a new kernel-package containing a new make-kpkg script and pulling different dependencies like build-essential, binutils, etc. with it
Ok, my task is to compile a linux kernel v3.10.12 (or v3.19) and run it within a VirtualBox machine (architecture x86_64, system Ubuntu 16.04.1). I used to be able to compile kernel-v3.10.12 and kernel-v3.19 in Ubuntu 14.04 Trusty deployed on the build server with the compiler gcc-4.8 and launch the kernels under the VirtualBox machine I mentioned above, but now something goes wrong while starting a kernel compiled
For example, let's consider v3.10.12 being compiled and run
For building the kernel I utilize 'make-kpkg' script provided by Ubuntu aptitude's package 'kernel-package'. I build the kernel for x86_64 using gcc-4.8 as I have always been doing
Once 'make-kpkg' has compiled the kernel and gathered linux-headers it starts packing them into deb-packages what makes me able to execute 'dpkg -i' on them in the system and install them in a 'debian' way
Okey, supposing I did it. Then I am going to reboot the system
When I choose my compiled kernel in the grub menu, it writes in the screen "Loading linux kernel... Loading initial ramdisk", then the inscription disappears, the screen goes black and I see only a cursor in the form of underscore "_" sign in the top-left side of the screen. That's all. Nothing is going to happen further. The booting process seems to have stuck
I tried swapping make-kpkg for an old one (from Trusty), swapping compiler gcc-4.8.5 for gcc-4.9, gcc-4.7, even gcc-5.2 having made a couple of supplementations inside the directory include/linux/ for the support of gcc-5.2, but nothing has come off, the result still persists being the same
I tried the same actions (on the same Ubuntu 16.04.1 and tool-chain) with new kernels 4. series* (for example, 4.6) meaning building the kernels, packing them into *.deb packages and installing into the VirtualBox machine and rebooting the system, and everything goes correctly, I see debug messages in the screen like I have always seen. I tried to use gcc-4.7, gcc-4.8, gcc-4.9, gcc-5.4 and everything works, I am able to load the linux-kernel-v4.6 appropriately and completely. But when I build 3.10.12 (or 3.19) kernels I cannot boot them properly and cannot have figured out why it has been happening
Actually, what I have found out is that the deal is in the kernel but not in initrd because I managed to substitute the 'broken' kernel by a working one having left 'initrd' built together with the 'broken' kernel and the debug logging started appearing and the kernel was loading until a rootfs came out to be mounted, at that moment the kernel didn't manage to load it and left in initramfs mode
Has someone faced the same issue I am observing? Actually I am almost exhausted having been struggling with this trouble for days
Maybe someone has any recipes or suggestion how to get rid of the problem?
I even put the 'panic' function code exactly in the first line of the function "asmlinkage void __init start_kernel(void)" but nothing happened, still the same black screen
Can the problem be related to a new glibc being used by gcc compiling my kernel? Personally, I am not prone to think so but in the world of linux everything can happen. On the other hand maybe toolchain (ld, as) somehow has affected? I am kindly asking to provide me a help.
I am nearly assured that someone before me has already encountered such an issue, I would have been searching for a topic alike but didn't find anything resembling
Thank you in advance
Short Answer
It's a glibc kernel version mismatch, if you need this you could create the glibc package such that it supports the kernel version that you need, by using the --enable-kernel flag at configuration time.
Long Answer
It's highly likely that your glibc was compiled in such a way that it only works down to a certain version of linux. This is done with the help of the --enable-kernel flag at the configuration stage. Any version older than the one specified in --enable-kernel will be rejected by glibc as a consequence no program will ever be loaded, like the init program presumably systemd's init.
This is from the configuration help of glibc
--enable-kernel=version
This option is currently only
useful on GNU/Linux systems. The version parameter should have the form X.Y.Z and describes the smallest version of the Linux kernel the generated library is expected to support. The higher the version number is, the less compatibility code is added, and the faster the code gets.
Finally I succeeded in this problem
Actually what I have done is to have compiled an old gcc-4.8.5 with an old glibc-2.19 on the host-system where I build the old-versioned kernels.
Glibc-2.19 was compiled with an option --enable-kernel=3.10.12 and with headers of an old-versioned linux-3.10.12. The compiler has turned out to be like a 'cross-compiler' with usage of glibc-2.19. So, I built an old kernel with the version 3.10.12 with this 'cross-compiler', which uses glibc-2.19, and everything has started working in a proper way
Thanks for the help and directing me to a right way to solve the problem, but I am obliged to notice that the deal was in host-system's glibc used but not in target-system glibc used as I had been assumedly said (but maybe I misunderstood #iharob)

How can I compile a Linux executable for a different machine?

I've written a Linux program in C, and I'm trying to get it to run on a server system. It looks like everything should work, but when I try it, I get this:
/lib64/libc.so.6: version `GLIBC_2.14' not found (required by <program>)
/lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./libdbi.so.1)
(Where <program> is my program's name.)
So far as I can tell, my program only requires that version of GLIBC because libdbi does. I've tried compiling libdbi from source, and it still attempts to link to that version of GLIBC.
I don't own the server system (it's a shared system I run a website on, and have SSH access to), so I can't make any changes to it -- that's why the library file is in the same directory, and I've set LD_LIBRARY_PATH=.. Unfortunately I also don't have access to a compiler on it -- when I try to run GCC, I'm told "permission denied". It's run by a big corporation, and I'm only one customer; the chances of them making any changes at my request are essentially zero.
Is there any way to compile the program on my system so that it will work on the server?
Before I asked, I found these similar questions:
Compile C program in Linux with different glibc library: the link in the answer goes to a 404 page, and from what I've been able to determine, apgcc isn't available on Debian distributions.
Relink a shared library to a different version of libc: seems to say that this problem doesn't exist, because "glibc tend to be backwards compatible" (except they apparently aren't in this case).
How to compile Linux C program to run on another Linux machine?: suggests a chroot or virtual machine, which I've done before elsewhere, but how can I tell it to use a libc without that old GLIBC version?
is binary executable file portable: suggests static-linking, but libdbi dynamically-links to its driver files, so that apparently can't be done -- I get several errors referring to missing functions like ldopen.
There are others, but they seem to be variations on those.
I'd be willing to use a non-free solution (like one that I saw in another answer I can't find now) if I turn this into a commercial product, but for a single use it seems like massive overkill, not to mention the expense.
Is there any way to simply tell libdbi to link to a later GLIBC version, maybe? If not, is there any solution I've overlooked?
Big corporation or not, the least they owe you if you are paying for service in any way or being paid for development to meet a requirement is a careful description of the runtime environment so you can duplicate it on a development machine.
Then you must set out to systematically duplicate this environment. Since you're using libdbi you should be thorough. Database connections can exercise big chunks of the system API, so you want to have exactly the same version of Linux, gcc (even if you can't run it, you need to know the version other parts of the system were compiled with), and other tools and libraries. If you don't, you won't be able to have much confidence that your development machine tests translate to good behavior on the target.
A virtual machine is a good way to create a specialized development environment without messing up your existing one.
You must compile it on a machine that has the same version of glibc as the target machine, or an older version. shared library compatibility works in that direction only.
Find out what version of Linux the server uses, get a copy of it and install it in a VM
Virtualbox is good for this
You can use this environment for testing code as well as this particular compilation problem
You have the following options:
Compile your code on the server machine (which likely has gcc installed)
Compile your program with statically linked libraries (option -static for gcc)

How to start debugging?

I have learned C and I would like to start to improve open source software. I would like to hack away one irritating bug in GTK+. To see the bug I need to use Gedit.
How can I download the sources of GTK+ and gedit and compile both of them so that I can see where the bug is? And I have never used any debugger in Linux so is there somewhere a tutorial for that?
You can get information about downloading and compiling of gedit here:
http://projects.gnome.org/gedit/developers.html
My Debugger of choice is GDB:
http://www.gnu.org/software/gdb/
GDB is a console application that may be hard to handle for a beginner. Try an IDE like Eclipse that provides a GUI to GDB.
Almost all Linux debuggers are front-ends for or adaptations of the gdb debugger. You should therefore learn how to use this first, preferably by starting on
small programs of your own construction, not giant FOSS codebases. The gdb manual,
available from here is actually a pretty good tutorial.
The information on building and installing GTK+ should be here:
http://www.gtk.org/development.html
The sources should be here:
http://www.gtk.org/download-linux.html
You can check out gdb:
http://www.gnu.org/software/gdb/ That's a pretty standard linux debugger. I would spend time with it on something simple first, or get an IDE that uses it. Learning gdb can be worth the time though.
gdb is a dinosaur which should long since have been made extinct. Debugging is one area where (gasp!) Windows beats Unix. Having got that off my chest, I advise you to start with the Data Display Debugger (DDD) graphical front end to gdb. Yes, the GUI is quaint, but you will be far more productive, quicker, than if you start with gdb.
Also don't overlook valgrind for finding and diagnosing memory errors. The KDE project actually mandates use of valgrind; I'm not sure about Gnome.
It is possible that you won't see the bug if you download the latest gedit and gtk+ sources. It might be fixed in the latest sources or the latest sources might be different enough to not trigger your bug.
What Linux distribution are you running?
First of all I'd suggest consulting your distribution's bug database to see if someone has filed a similar bug. If you don't find anything, I'd suggest using your distribution's tools to obtain the source that corresponds to the binary that you have installed on your sytem (e.g. apt-get source libgtk-2.0 on Debian or Ubuntu).
Also, your distribution might also make a debug package available (e.g. libgtk2.0-0-dbg on Debian) which will let you run a debugger on the binary that you already have without requiring the source. While this is no substitute for having the sources, it can be useful for running valgrind or making sense out of a core file.

Resources