basic scheduling, basic syscall, (added .data copy)
[cortex-from-scratch] / main.c
diff --git a/main.c b/main.c
index 1543a12..ac01416 100644 (file)
--- a/main.c
+++ b/main.c
@@ -16,6 +16,7 @@
 
 #include <sys/robsys.h> 
 #include <sys/mmap.h>
+#include <sys/process.h>
 
 #include <lib/regfunc.h>
 #include <lib/pool.h>
 //#include <drivers/mk450_joystick.h>
 #include <drivers/st7735s.h>
 
-
 #include <lib/syscall.h>
 
 
+process_t p1;
+process_t p2;
+
+uint32_t stackp1[500];
+uint32_t stackp2[500];
+
+extern int count;
+
+void switch_usermode() {
+
+       // user mode 
+       //asm volatile ("mov r0, 0x1" "\n\t" 
+       //"msr control, r0" "\n\t"
+       //"isb" "\n\t"); 
+
+       // system init call
+
+}
+
+void process1(void) {
+       
+       while(1) {
+               //uint32_t control = 0xFFFFFFFF;
+               printf("process 1\n");
+               //asm volatile("msr control, %0" "\n\t"
+               //             "dsb" : : "r" (control));
+               //printf("control: %x", control);       
+               //for(;;);
+               _block(100);
+               theos_switch(&p1, &p2);
+       }
+
+}
+void process2(void) {
+       while(1) {
+               printf("process 2\n");
+               _block(100);
+               theos_switch(&p2, &p1);
+       }
+       
+}
+
+int test_data_segment = 99;
+
 void main()
 {
 
+       /* Load .data segment into SRAM */
+       extern uint32_t * data_lma, data_vma, data_end;
+       int size = (&data_end - &data_vma) * 4;
+       memcpy(&data_vma, &data_lma, size);
+
        /* Initialize the clock system, */
        clock_init();
 
@@ -50,11 +99,6 @@ void main()
        /* TFT screen */
        // tft_init();
        
-       /* Cortex M* integrated systick, can be replaced
-        * by the more accurate RTC.
-       systick_init();
-       */
-       
        /* Set up a very small libc library */
        init_printf(NULL, putc);
 
@@ -68,14 +112,42 @@ void main()
        /* On board LEDs*/
        led_init();
 
+
        /* Real time clock */
-       //rtc_init();
+       rtc_init();
+
 
 //     printf("press any key to start\n");
-//     asm volatile ("wfi");
+//     asm volatile ("cpsid f"); // doesn't work in qemu
 
        syscall_init();
-       theos_test(0xA1, 0xA2);
+
+       //int ret;
+       //ret = theos_test(0x1, 0x2, 0x3);
+       //ret = theos_uptime();
+
+       //printf("ret: %d\n", ret);
+
+       int size_stack = sizeof(stackp1);
+       
+       p1.stackptr = ((unsigned int) stackp1) + size_stack - 0x1C;
+       p1.stackptr[6] = (uint32_t) process1;
+       p1.stackptr[7] = 0x01000000;
+       p2.stackptr = ((unsigned int) stackp2) + size_stack - 0x1C;
+       p2.stackptr[6] = (uint32_t) process2;
+       p2.stackptr[7] = 0x01000000;
+       
+       theos_init(&p1);
+
+       /* Cortex M* integrated systick, can be replaced
+        * by the more accurate RTC. */
+       
+//     systick_init();
+
+       //      switch_usermode();      
+
+       //printf("without system call");        
+//     theos_test(0xA1, 0xA2);
 
        /* Eeprom Driver
        eeprom_at24c_init();