Skip to content
Snippets Groups Projects
Commit 5085f973 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

Resume execution after power loss

parent a2f5c26a
No related branches found
No related tags found
No related merge requests found
...@@ -42,10 +42,12 @@ int main(void) ...@@ -42,10 +42,12 @@ int main(void)
gpio.setup(); gpio.setup();
kout.setup(); kout.setup();
//restore_state();
gpio.led_on(0); gpio.led_on(0);
gpio.input(GPIO::p4_5, 1); gpio.input(GPIO::p4_5, 1);
asm_load_all();
kout << "Hello, World!" << endl; kout << "Hello, World!" << endl;
arch.idle_loop(); arch.idle_loop();
......
...@@ -8,12 +8,18 @@ stack_backup: ...@@ -8,12 +8,18 @@ stack_backup:
sp_backup: sp_backup:
.space 2 .space 2
backup_cookie:
.space 2
asm_save_all: asm_save_all:
dint dint
.irp reg,4,5,6,7,8,9,10,11 .irp reg,4,5,6,7,8,9,10,11
push r\reg push r\reg
.endr .endr
mov #1234h, r10
mov r10, &backup_cookie
mov r1, &sp_backup mov r1, &sp_backup
mov #1c00h, r10 mov #1c00h, r10
...@@ -34,6 +40,15 @@ save_sram_word: ...@@ -34,6 +40,15 @@ save_sram_word:
asm_load_all: asm_load_all:
dint dint
push r11
mov &backup_cookie, r11
cmp #1234h, r11
jeq do_load_all
pop r11
eint
ret
do_load_all:
; restore SRAM from backup ; restore SRAM from backup
mov #stack_backup, r10 mov #stack_backup, r10
mov #1c00h, r11 mov #1c00h, r11
...@@ -59,32 +74,32 @@ load_sram_word: ...@@ -59,32 +74,32 @@ load_sram_word:
asm_load_mem: asm_load_mem:
dint dint
; save return address in r4
mov @r1, r4
; restore SRAM from backup push r11
mov &backup_cookie, r11
cmp #1234h, r11
jeq do_load_mem
pop r11
eint
ret
do_load_mem:
push r10
push r9
; restore SRAM from backup, excluding current stack frame
mov r1, r9
sub 6, r9
mov #stack_backup, r10 mov #stack_backup, r10
mov #1c00h, r11 mov #1c00h, r11
load_sram_word2: load_sram_word2:
mov @r10+, 0(r11) mov @r10+, 0(r11)
add #2, r11 add #2, r11
cmp #1c00h+2048, r11 cmp r9, r11
jlo load_sram_word2 jlo load_sram_word2
; restore stack pointer pop r9
mov &sp_backup, r1 pop r10
pop r11
; restore old register contents
.irp reg,11,10,9,8,7,6,5
pop r\reg
.endr
; load return address, that is, the address this function was called from.
; This is not the address which called asm_save_all -- we only want to restore memory contents, not re-execute everything
mov r4, 2(r1)
; load remaining register content
pop r4
eint eint
ret ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment