The process by which the cerebral cortex generates movements to achieve different tasks remains poorly understood. Here, we leveraged the rich repertoire of well-controlled primate locomotor behaviors to study how task-specific movements are encoded across the dorsal premotor cortex (PMd), primary motor cortex (M1), and primary somatosensory cortex (S1) under naturalistic conditions. Neural population activity was confined within low-dimensional manifolds and partitioned into task-dependent and task-independent subspaces. However, the prevalence of these subspaces differed between cortical regions. PMd primarily operated within its task-dependent subspace, while S1, and to a lesser extent M1, largely evolved within their task-independent subspaces. The temporal structure of movement was encoded in the task-independent subspaces, which also dominated the PMd-to-M1 communication as the movement plans were translated into motor commands. Our results suggest that the brain utilizes different cortical regions to serialize the motor control by first performing task-specific computations in PMd to then generate task-independent commands in M1.