Question

In xv6 MIT operating system, I'm trying to understand what is the different between the a few putc functions in /xv6/console.c

  1. static void cgaputc(int c).
  2. void uartputc (int c).
  3. static void constputc(int c).

Thanks!

Was it helpful?

Solution

consputc() is a console output function. It writes a char to the console, which in that OS appears to mean both the serial port and the CGA text display. Before doing that, it first checks if the system has panicked (a panic is the state which the kernel enters when it has encountered an error and doesn't know what to do, so instead of going ahead and probably making matters worse decides to panic and stop), and if so, enters an infinite loop with interrupts disabled, so only a system reset can leave the panic state.

uartputc() writes a char to the serial port. It first checks that the serial port is not busy, and will accept the char.

cgaputc() writes a char to the CGA text framebuffer, and adjust the cursor position accordingly. The CGA text framebuffer starts at address 0xb8000, and consists of interleaved (attribute, character) bytes. The default mode, mode 3 is a 80x25 (80 columns, 25 rows) text mode. Attribute 07 means gray text on black background. The cursor position is manipulated via the CRT controller port, which exposes several registers, registers 14 and 15 hold the cursor position as 14 bits. The CRTC is accessed by first selecting a register to access by writing its number to the index CRTC port at 0x3d4, and then writing or reading from the CRTC control/data port at 0x3d5. This stuff is documented in a document called vgadoc4b, and in Ralph Brown's interrupt list.

OTHER TIPS

You can see what all these functions do if you consult the code.

consputc(int c) clears interrupts then calls uartputc() and then calls cgaputc().

uartputc(int c) uses in and out to write c to the serial port (UART)

cgaputc(c) appears to be a console input/output function. Writes c to the serial port or the console, and it also sets the position of the cursor and sets the color for the console (black on white)

That's what I get from reading the code anyway, I have not used these functions before, but it seems pretty straight forward.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top