The mapping from ports and pins is done in:
hardware/arduino/variants/TYPE/pins_arduino.h
The "TYPE" (standard, mega, leonardo, eightanaloginputs) is specified in the boards.txt file:
uno.build.variant=standard
You could add your own variant called, for example "barechip386P" and map pin numbers to ports and pins any way you like.