NSWI200: Operating Systems
Lubomír Bulej (bulej@d3s.mff.cuni.cz)
Vojtěch Horký
(horky@d3s.mff.cuni.cz)
Viktor Fuglík (viktor.fuglik@matfyz.cuni.cz)
printf list_t linked list typeprintf to kernel codeprintk into one kernel kmalloc and kfree… complete all milestones before mid January (baseline tests must work).
my_printflist_t and link_tmy_printf(const char* format, ...)Print the format string, replacing % directives with
actual arguments.
Supported directives:
char) via %cint) in decimal via
%dunsigned int) in hexadecimal via
%x and %Xchar *) via
%svoid *) in hexadecimal via
%pNo need to implement width, precision, length modifiers and other flags.
Extension:
%pL for printing lists (list_t)%pT to print struct timespec *%pB to print byte bufferstatic void print_strings(const char* header, ...) {
puts(header);
va_list args;
va_start(args, header);
const char *argument = va_arg(args, const char *);
while (argument != NULL) {
printf(" - '%s'\n", argument);
argument = va_arg(args, const char *);
}
va_end(args);
}
...
print_arguments("Start of alphabet", "a", "b", "c", NULL);
print_arguments("No arguments", NULL);
print_arguments("Bad usage", "a", "b", NULL, "never printed", NULL);Nothing more complex will be needed or required (this is OS course, not ADS).
Our lists will have maximum of tens (or very low hundreds) of items.
Do not implement them yourself. Seriously.
Switch to more complex data structure only when:
And even then: think twice (and reuse the code from Linux or HelenOS, please).
list_t list;
list_init(&list);
payload_t * payload = create_payload();
payload->value = 42;
list_item_t * item = create_list_item();
item->data = payload;
list_append(&list, item);list_t list;
list_init(&list);
payload_t * payload = create_payload();
payload->value = 42;
link_init(&payload->link);
list_append(&list, &payload->link);my_printf to kernel and some othe bits ./configure.py [--kernel-test=(printk/int|...)]makemsimmake distclean for a different test./tools/tester.py suite suites/*.txt