********************** OS/161 - kprintf() ********************** .. topic:: Learning Outcome Able to apply kprintf and understand its limitations. .. topic:: Introduction *kprintf()* is a function which prints to the OS/161 console. It behaves very similar *printf()* that you may be familiar with, except that it is used internally to the operating system, and it only prints to the operation system console. .. topic:: Applicable subjects COMP3231 ---- kprintf() ============ Print a formatted string to the terminal from within the OS/161 kernel. :: int kprintf(const char *format, ...); Returns the number of characters displayed. Its arguments are the same as those to *printf()*. Suitable Uses ============= * Messages to the terminal *kprintf()* is useful for printing OS menu options to the terminal. * Basic debugging *kprintf()* can be used to generate a log of activity within the operating system that can be audited to understand the OS behaviour. Cautions =========================== * *kprintf()* is dependent on OS/161's internal console driver, which has the following implications. * *kprintf()* output does not appear until the console driver is initialised. It can't be used to debug problems early in the OS/161 startup. * If the console driver is corrupted, *kprintf()* output also does not appear. * The *kprintf()* console driver triggers context switches (blocks and unblocks). * This changes the timing behaviour of any code calling *kprintf()*, which can hide race conditions (i.e. bugs dependent on timing). * It results in TLB flushes, so **BE CAREFUL DEBUGGING ASSIGNMENT 3 CODE**. When writing a TLB refill handler, a context switch flushes the TLB and ejects the entry you have just loaded, causing an infinite loop. * *kprintf()* may change the behaviour of code (memory layout and timing) as it is debugging from within the system. In contrast, GDB allows you to observe the behaviour without affecting its execution. .. moduleauthor:: Liz Willer :Date: 2020-01-30