Factor out of platform code from sf-demo.c to platform.c