start with assignment 4.4
This commit is contained in:
@@ -170,3 +170,47 @@ and when the 'malicious' code is removed, it functions as normal.
|
||||
|
||||
> Tasks are no longer able to access the SysTick peripheral. It is time to implement a system call using the SVC interrupt mechanism. The `taskYield()` function would also classify as a system call. Write a system call function that will allow a task to change the SysTick period to a value between 1 and 10 ms . The system call should utilize the SVC mechanism by passing a different number than the `taskYield()` call. Make sure both calls keep working! Within the SVC interrupt service routine you will have to find the used SVC instruction using the PC value and look at the LSB to determine the system call number. You can also utilize the tasks’ stack to find the passed SysTick period parameter. When this parameter is invalid the system call should simply return.
|
||||
|
||||
### user
|
||||
```
|
||||
instrucion: 0x08000600 -> 00060008
|
||||
SP: 0x20000484
|
||||
```
|
||||
|
||||
### kernel
|
||||
|
||||
```
|
||||
psp: 0x20000460
|
||||
|
||||
0x20000400 : 0x20000400 <Hex>
|
||||
Address 0 - 3 4 - 7 8 - B C - F
|
||||
20000430 04000000 05000000 06000000 74040020
|
||||
20000440 08000000 09000000 0A000000 0B000000
|
||||
20000450 1F030000 01000000 1F030000 B0000020
|
||||
20000460 1F030000 01000000 1F030000 B0000020
|
||||
20000470 0C000000 F1060008 62060008 00020001
|
||||
20000480 88040020 88040020 07000000 FDFFFFFF
|
||||
20000490 807505D0 022C0CBF 4FF40075 4FF44075
|
||||
200004A0 082815D1 CB4C2068 20F44070 20602068
|
||||
200004B0 28432060 206840F0 04002060 206840F4
|
||||
200004C0 80302060 00F040F9 216821F0 04012160
|
||||
200004D0 F0000020 00000000 00000000 14050020
|
||||
|
||||
PSP+(8*4): 88040020 -> 20000488
|
||||
|
||||
0x20000400 : 0x20000400 <Hex>
|
||||
Address 0 - 3 4 - 7 8 - B C - F
|
||||
20000440 08000000 09000000 0A000000 0B000000
|
||||
20000450 1F030000 01000000 1F030000 B0000020
|
||||
20000460 1F030000 01000000 1F030000 B0000020
|
||||
20000470 0C000000 F1060008 62060008 00020001
|
||||
20000480 88040020 88040020 07000000 FDFFFFFF
|
||||
20000490 807505D0 022C0CBF 4FF40075 4FF44075
|
||||
200004A0 082815D1 CB4C2068 20F44070 20602068
|
||||
200004B0 28432060 206840F0 04002060 206840F4
|
||||
200004C0 80302060 00F040F9 216821F0 04012160
|
||||
200004D0 F0000020 00000000 00000000 14050020
|
||||
200004E0 00000000 00000000 00000000 00000000
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ void writePSP(void * ptr);
|
||||
void returnToPSP(void);
|
||||
void returnToMSP(void);
|
||||
void toUnprivileged(void);
|
||||
uint32_t* getStackpointer(void);
|
||||
|
||||
#define TASK_MASK MAX_TASKS-1
|
||||
#define IDLE_TASK MAX_TASKS
|
||||
@@ -250,8 +251,27 @@ void PendSV_Handler(void)
|
||||
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
taskToExecute = schedule();
|
||||
SCB->ICSR |= (1<<28);
|
||||
uint32_t* sp = getStackpointer();
|
||||
|
||||
|
||||
|
||||
uint8_t svc_id = 1;
|
||||
|
||||
switch (svc_id)
|
||||
{
|
||||
case 1: // taskYield
|
||||
taskToExecute = schedule();
|
||||
SCB->ICSR |= (1<<28);
|
||||
break;
|
||||
|
||||
case 2: // setSysTick_10ms
|
||||
SysTick->LOAD = 10 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
|
||||
case 3: // setSysTick_1ms
|
||||
SysTick->LOAD = 1 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Call Super Visor
|
||||
@@ -267,4 +287,12 @@ void delay(uint32_t ticks)
|
||||
taskYield();
|
||||
}
|
||||
|
||||
void setSysTick_10ms(void)
|
||||
{
|
||||
asm(" svc #2");
|
||||
}
|
||||
|
||||
void setSysTick_1ms(void)
|
||||
{
|
||||
asm(" svc #3");
|
||||
}
|
||||
|
||||
@@ -23,5 +23,7 @@ void addTaskToList(void(*function)(void), uint32_t stackSize, int8_t priority);
|
||||
void startVersdOS(uint16_t sysTickPeriodIn_ms);
|
||||
|
||||
void delay(uint32_t ticks);
|
||||
void setSysTick_10ms(void);
|
||||
void setSysTick_1ms(void);
|
||||
|
||||
#endif /* VERSDOS_H_ */
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
.global returnToPSP
|
||||
.global returnToMSP
|
||||
.global toUnprivileged
|
||||
.global getStackpointer
|
||||
// .global SVC_Handler
|
||||
|
||||
pushRegistersToCurrentPSP:
|
||||
@@ -51,3 +52,7 @@ toUnprivileged:
|
||||
ORR R0, R0, #1 // clear bit 0 (nPRIV)
|
||||
msr CONTROL, R0 // copy R0 to control register
|
||||
bx lr
|
||||
|
||||
getStackpointer:
|
||||
mov R0, SP
|
||||
bx lr
|
||||
|
||||
@@ -56,6 +56,10 @@ void toggleBlue(void)
|
||||
{
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
setSysTick_10ms();
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
setSysTick_1ms();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user