began work to add privilege

master
tcsullivan 6 years ago
parent 79da473bd0
commit 04548126b5

@ -0,0 +1,26 @@
#ifndef PRIV_GPIO_H_
#define PRIV_GPIO_H_
#define GPIO_MODE 0
#define GPIO_TYPE 1
#define GPIO_PUPD 2
#define GPIO_SPEED 3
#define GPIO_OUT 4
void gpio(uint32_t call, uint32_t port, uint32_t pin, uint32_t value)
{
register uint32_t r0 asm("r0") = call;
register uint32_t r1 asm("r1") = port;
register uint32_t r2 asm("r2") = pin;
register uint32_t r3 asm("r3") = value;
asm("\
mov r0, %0; \
mov r1, %1; \
mov r2, %2; \
mov r3, %3; \
svc 1; \
" :: "r" (r0), "r" (r1), "r" (r2), "r" (r3));
}
#endif // PRIV_GPIO_H_

@ -20,6 +20,27 @@
#include <gpio.h> #include <gpio.h>
void gpio_svc(uint32_t *args)
{
switch (args[0]) {
case 0:
gpio_mode((GPIO_TypeDef *)args[1], args[2], args[3]);
break;
case 1:
gpio_type((GPIO_TypeDef *)args[1], args[2], args[3]);
break;
case 2:
gpio_pupd((GPIO_TypeDef *)args[1], args[2], args[3]);
break;
case 3:
gpio_speed((GPIO_TypeDef *)args[1], args[2], args[3]);
break;
case 4:
gpio_dout((GPIO_TypeDef *)args[1], args[2], args[3]);
break;
}
}
void gpio_init(void) void gpio_init(void)
{ {
// enable clocks // enable clocks

@ -20,6 +20,7 @@
#include <clock.h> #include <clock.h>
#include <gpio.h> #include <gpio.h>
#include <priv_gpio.h>
#include <heap.h> #include <heap.h>
#include <stm32l476xx.h> #include <stm32l476xx.h>
#include <task.h> #include <task.h>
@ -53,19 +54,29 @@ int main(void)
void task2(void); void task2(void);
void kmain(void) void kmain(void)
{ {
gpio_mode(GPIOA, 5, OUTPUT); gpio(GPIO_MODE, (uint32_t)GPIOA, 5, OUTPUT);
//gpio_mode(GPIOA, 5, OUTPUT);
task_start(task2, 512); task_start(task2, 512);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
gpio_dout(GPIOA, 5, !(i & 1)); gpio_dout(GPIOA, 5, !(i & 1));
delay(200); delay(200);
} }
return;
} }
void task3(void);
void task2(void) void task2(void)
{ {
while (1) delay(400);
delay(800); task_start(task3, 1024);
}
void task3(void)
{
int state = 0;
delay(2500);
while (1) {
gpio_dout(GPIOA, 5, state ^= 1);
delay(500);
}
} }

@ -0,0 +1,53 @@
/**
* @file svc.c
* An unused handler for SVC calls
* TODO: use SVC calls, possibly allowing for switch to unprivileged mode?
*
* Copyright (C) 2018 Clyne Sullivan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <gpio.h>
#include <clock.h>
extern void gpio_svc(uint32_t *);
void svc_handler(uint32_t *args)
{
uint32_t svc_number = ((char *)args[6])[-2];
switch (svc_number) {
case 1:
gpio_svc(args);
break;
default:
break;
}
}
void SVC_Handler(void) {
uint32_t *args;
asm("\
tst lr, #4; \
ite eq; \
mrseq %0, msp; \
mrsne %0, psp; \
" : "=r" (args));
svc_handler(args);
}
Loading…
Cancel
Save