printk: rework code

Signed-off-by: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>
stlinky: size_t -> int, newlib uses int anyway

Signed-off-by: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>