In PTP 1588, timestamped packets means the time when first bit of PTP packet leaves the device pin?
Does that mean if that time has to be fed in the packet, PTP stack should know how much time from a given stage in PTP stack till the device pin will be taken by that PTP packet?
so that time can be pre-fed in the packet?
Yes I think the IEEE1588 standard does have a definition where exactly the time stamping point is. It is not so important where exactly this point is, because the delay (as long as it is a constant delay) will be compensated.
Usually when you use PTP, you have a hardware timestamping unit (TSU) which has a digital clock that can be adjusted from software. Timestamping can be either be implemented in the PHY (the chip that drives the wire), or in the MAC (the periphery of the CPU that buffers the frames until the software has time to read them).
When a PTP frame is recognized, usually the current timestamp plus the PTP sequence number and message type are stored into a separate memory for the CPU to fetch later. The CPU will then use this information to adjust the clock of the TSU (usually not the same as to the normal system time seen from the OS). The TSU clock is then used by application-programmed hardware, e.g. to timestamp external signals, or to generate precise pulses. It is usually not used directly by the software, because that would add back many of the unpredictable latencies that were avoided by having hardware timestamping.
You cannot just append the timestamp to the frame, because then the CPU cannot get any transmit timestamps. If the software does any kind of timestamping on the CPU, the precision of PTP is usually lost, because of a lot of uncertainties (like interrupt latency, scheduler latency, queues, etc.)
However, PTP frames also contain a correction field which can be adjusted on the fly by hardware components, e.g. a switch may add the forwarding delay directly into the frame, modifying it on the fly, and calculating a new checksum.