I would like to dynamically allocate memory from an assembly
program that does not link against the standard C library.
Since brk(2) and sbrk(2) are unavailable on Mac OS X (10.6.2),
what are the alternatives?
(I'm guessing that it involves a Mach call, but there seems to
be little documentation around that)
Probably the easiest thing to do is look at the Darwin sources and see how malloc works internally.
Looks like malloc calls mmap, which calls __mmap, which looks like it's just a syscall
Related
I have a student task to read PCI info via 0xCF8 and 0xCFC ports using outl(), inl() functions. It assumes I use Linux x86, but can I do such things on macos with M1 chip?
I found <sys/uio.h> header but it does not define functions prototypes.
outl and inl are platform-specific functions for Linux. If it is an exercise, and you have to submit a code snippet, then I suggest installing some kind of virtual machine (VirtualBox or maybe Docker Desktop) and write a program for Linux, otherwise your code would be unlikely to be accepted, since it'd use completely different low-level API.
In Xcode's Instruments, there is a tool called Counters that exposes low-level counter information provided by the CPU, such as the number of instructions executed or number of cache misses:
This is similar to the Linux syscall perf_event_open introduced in Linux 2.6.32. On Linux, I can use perf_event_open then start/stop profiling around the section of my code I'm interested in. I'd like to record the same type of stats on OS X: counting the instructions (etc.) that a certain piece of code takes, and getting the result in an automated fashion. (I don't want to use the Instruments GUI to analyze the data.)
Are there any APIs that allow this (ex: using dtrace or similar)? From some searching it sounds like the private AppleProfileFamily.framework might have the necessary hooks, but it's unclear how to go about linking to or using it.
In GNU/Linux I use Intel's PCM to monitor CPU utilization. I'm not sure if this works fine on OSX, but as far as I know the source-code is including the MacMSRDriver directory. I have no any OSX device, never test it anyway.
In case this source compiled on your device, Just run:
pcm.x -r -- your_program your_program_parameter
or if you want advanced profiling, use pcm-core.x instead or you can build your own code based on pcm-core.cpp
There is a command called debug in windows that can manage register and memory, like change the value in ax, etc, is there any similar tool on Mac OS X?
I find a man page of reg, https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/reg.1.html, it seems to be the tool I am looking for, but I cannot find it in my os, I am using mac os x 10.10
I think what you want to do is compile a program that has the assembly you are interested in (either start with C or write some assembly code by hand if you want.) Then run it under the debugger (lldb or Xcode.) Set some breakpoints at places that are interesting to you, run the program. Then when you hit the breakpoint you set, you can use register read and register write to poke at the registers, or memory read and memory write to poke at memory.
We have built a simple instruction set simulator for the sparc v8 processor. The model consists of a v8 processor, a main memory and a character input and a character output device. Currently I am able to run simple user-level programs on this simulator which are built using a cross compiler and placed in the modeled main memory directly.
I am trying to get a linux kernel to run on this simulator by building a simplest bootloader. (I'm considering uClinux which is made for mmu-less systems). The uncompressed kernel and the filesystem are both assumed to be present in the main memory itself, and all that my bootloader has to do is pass the relevant information to the kernel and make a jump to the start of the kernel code. I have no experience in OS development or porting linux.
I have the following questions :
What is this bare minimum information that a bootloader has to supply to the kernel ?
How to pass this information?
How to point the kernel to use my custom input/output devices?
There is some documentation available for porting linux to ARM boards, and from this documentation, it seems that the bootloader passes information about the size of RAM etc
via a data structure called ATAGS. How is it done in the case of a Sparc processor? I could not find much documentation for Sparc on the internet. There exists a linux bootloader for the Leon3 implementation of Sparc v8, but I could not find the specific information I was looking for in its code.
I will be grateful for any links that explain the bare minimum information to be passed to a kernel and how to pass it.
Thanks,
-neha
Is there a way to step into OpenCL kernel code running on a CPU device (MAC)?
I can use printfs but I would like to step into kernel code.
I believe not. The ability is not mentioned in the "Debugging" section of the OpenCL for OSX documentation (and PDF).