how does serial port library actually work under the hood..?

im just looking for how to send/ write date to pc over serial port from arduino..vice versa.

I have few Question to ask after taking so much time and couldn't figure it out myself. I hope you guys can guid me please.

First, i found i can use Serial.println() function to send some data then, on the pc side, it just checks and reads the port (/dev/tty..). But, how does this process actually work under the hood? So, if you use serial.println() it knows about where to write?

Second i also found it's something to do with UART communication.. But, inside Hardware.cpp file, i couldn't find any function call to the one for UART.

Third there is the code like extern HardwareSerial Serial; Then where is the definition of this Serial?

Fourth There seem to have ring buffer for serial buffer. So, when data is being sent then, what and who fill the data into this buffer inside Hardware.cpp?

please, forgive my silly question.. i'm just so curious about this..

An UNO has a single hardware UART port to send/receive TTL level serial data. The port can only accept a single 8/9 bit frame at a time so the serial library has a built in ring buffer to store your print data and feed it a byte at a time to the hardware UART using interrupts while your code is still running (if you fill the buffer then the print command will not return control to you until there is space in the buffer).
I think the library also has a receive buffer that stores incoming serial data until you read it (or it overflows and further data is lost) as the hardware UART is only 1 or 2 bytes in size.

Third there is the code like extern HardwareSerial Serial; Then where is the definition of this Serial?

Big clue: extern HardwareSerial Serial;