Ejemplo n.º 1
0
void kloader_cmain(struct mem_map_entry mem_map[], uint32_t mem_entry_count)
{
    screen_init();
    screen_cursor_hide();
    terminal_init();

    KINFO("Welcome to Nox (Bootloader mode)");

    mem_mgr_init(mem_map, mem_entry_count);

    ata_init();
    fs_init();

    struct fat_part_info* part_info = fs_get_system_part();
    struct fat_dir_entry kernel;
    if(!fat_get_dir_entry(part_info, "KERNEL  ELF", &kernel)) {
        KPANIC("Failed to locate KERNEL.ELF");
        while(1);
    }

    intptr_t kernel_entry_point;

    if(!elf_load_trusted("KERNEL  ELF", &kernel_entry_point)) {
        KWARN("Failed to load elf!");
    } 

    kernel_entry cmain = (kernel_entry)(kernel_entry_point);

    cmain(mem_map, mem_entry_count);


    KINFO("Bootloader done");

    while(1);
}
Ejemplo n.º 2
0
void task_sys_init(void* p_data)
{
  BOOL ret = FALSE;
  u32* pstack_pnt = NULL;
  mem_mgr_partition_param_t partition_param = { 0 };
  
  //init memory manager, to the memory end
  mem_mgr_init(g_sys_mem, SYS_MEMORY_END);
  
  /* create SYS partition */
  partition_param.id   = MEM_SYS_PARTITION;
  partition_param.size = SYS_PARTITION_SIZE;
  partition_param.p_addr = g_sys_mem;
  partition_param.atom_size = SYS_PARTITION_ATOM;
  partition_param.user_id = SYS_MODULE_SYSTEM;
  partition_param.method_id = MEM_METHOD_NORMAL;
  ret = MEM_CREATE_PARTITION(&partition_param);
  MT_ASSERT(FALSE != ret);
  OS_PRINTF("create patition ok!\n");
  
  //register malloc/free function, using system partition
  mtos_mem_init(my_malloc, my_free);
  OS_PRINTF("init mem ok!\n");

  mtos_ticks_init(SYS_CPU_CLOCK);

  //init message queue
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);

#ifdef CORE_DUMP_DEBUG
  //start statistic task, MUST BE in the first task!
  mtos_stat_init();
#endif

  //create timer task
  pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STKSIZE);
  MT_ASSERT(pstack_pnt != NULL);
  
  ret = mtos_task_create("Timer",
         Task_SysTimer,
         (void *)0,
         SYS_TIMER_TASK_PRIORITY,
         pstack_pnt,
         SYS_TIMER_TASK_STKSIZE);

  MT_ASSERT(FALSE != ret);
  OS_PRINTF("create timer task ok!\n");

  mtos_task_sleep(25);
  OS_PRINTF("start ap init!\n");
  ap_init();
  OS_PRINTF("ap init ok!\n");
  
  mtos_task_exit( );
}
Ejemplo n.º 3
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo, keycmd;
  int  fifobuf[128], keycmd_buf[32];
  char debug_info[64];
  int mouse_x, mouse_y, cursor_x, cursor_c;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  layer_t* cons_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  unsigned char* cons_buf;
  static char s_keytable[0x80] = {
    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 
    0,   '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0
  };
  static char s_keytable_shift[0x80] = {
    0,   0,   '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"','~', 
    0,   '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0
  };
  task_t* task_a;
  task_t* task_cons;
  timer_t* timer;
  int key_to = 0, key_shift = 0;
  int key_leds = (binfo->leds >> 4) & 7;  /* CapsLock state */
  int keycmd_wait = -1;
  console_t* console;
  int j, x, y;
  int movemode_x = -1, movemode_y = -1;
  layer_t* layer = 0;


  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128, 0);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */
  fifo_init(&keycmd, keycmd_buf, 32, 0);

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  task_a = task_init(mem_mgr);
  fifo.task = task_a;
  task_run(task_a, 1, 2);
  *((int*)0x0fe4) = (int)layer_mgr;

  /* back layer */
  back_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);

  /* console task */
  cons_layer = layer_alloc(layer_mgr);
  cons_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 256 * 165);
  layer_setbuf(cons_layer, cons_buf, 256, 165, -1); /* transparent */
  make_window8(cons_buf, 256, 165, "Console", 0);
  make_text8(cons_layer, 8, 28, 240, 128, COLOR8_000000);
  task_cons = task_alloc();
  task_cons->tss.esp = 
    mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 12;
  task_cons->tss.eip = (int)&console_task;
  task_cons->tss.es  = 1 * 8;
  task_cons->tss.cs  = 2 * 8;
  task_cons->tss.ss  = 1 * 8;
  task_cons->tss.ds  = 1 * 8;
  task_cons->tss.fs  = 1 * 8;
  task_cons->tss.gs  = 1 * 8;
  *((int*)(task_cons->tss.esp + 4)) = (int)cons_layer;
  *((int*)(task_cons->tss.esp + 8)) = memory_total;
  task_run(task_cons, 2, 2);  /* level = 2, priority = 2 */
  
  /* window layer */
  win_layer = layer_alloc(layer_mgr);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(win_layer, win_buf, 144, 52, -1);
  make_window8(win_buf, 144, 52, "TASK-A", 1);
  make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF);
  cursor_x = 8;
  cursor_c = COLOR8_FFFFFF;
  timer = timer_alloc();
  timer_init(timer, &fifo, 1);
  timer_settimer(timer, 50);

  /* mouse layer */
  mouse_layer = layer_alloc(layer_mgr);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  init_mouse_cursor8(mouse_buf, 99);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;

  layer_slide(back_layer, 0, 0);
  layer_slide(cons_layer, 32, 4);
  layer_slide(win_layer, 64, 56);
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_updown(back_layer, 0);
  layer_updown(cons_layer, 1);
  layer_updown(win_layer, 2);
  layer_updown(mouse_layer, 3);


  fifo_put(&keycmd, KEYCMD_LED);
  fifo_put(&keycmd, key_leds);

  for ( ; ; ) {
    if (fifo_size(&keycmd) > 0 && keycmd_wait < 0) {
      /* send it when send data to keyboard controller */
      keycmd_wait = fifo_get(&keycmd);
      wait_kbc_sendready();
      io_out8(PORT_KEYDATA, keycmd_wait);
    }

    io_cli();

    if (0 == fifo_size(&fifo)) {
      task_sleep(task_a);
      io_sti();
    }
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
        if (data < (256 + 0x80)) {
          /* translation character */
          if (0 == key_shift)
            debug_info[0] = s_keytable[data - 256];
          else 
            debug_info[0] = s_keytable_shift[data - 256];
        }
        else 
          debug_info[0] = 0;
        if ('A' <= debug_info[0] && debug_info[0] <= 'Z') {
          /* it's an english character */
          if ((0 == (key_leds & 4) && 0 == key_shift) 
            || (0 != (key_leds & 4) && 0 != key_shift))
            debug_info[0] += 0x20;  /* character lower ('A' -> 'a') */
        }
        if (0 != debug_info[0]) {
          /* general character */
          if (0 == key_to) {
            /* send character data to TASK-A */
            if (cursor_x < 128) {
              /* display one character and cursor move backward one */
              debug_info[1] = 0;
              drawstring_and_refresh(win_layer, cursor_x, 28, 
                  COLOR8_000000, COLOR8_FFFFFF, debug_info, 1);
              cursor_x += 8;
            }
          }
          else  /* send character data to console window */
            fifo_put(&task_cons->fifo, debug_info[0] + 256);
        }

        if ((256 + 0x0e) == data) {
          /* backspace, recover cursor by sapce, move back cursor 1 time */
          if (0 == key_to) {
            if (cursor_x > 8) {
              drawstring_and_refresh(win_layer, cursor_x, 28, 
                  COLOR8_000000, COLOR8_FFFFFF, " ", 1);
              cursor_x -= 8;
            }
          }
          else 
            fifo_put(&task_cons->fifo, 8 + 256);
        }
        if ((256 + 0x1c) == data) {
          /* Enter Key */
          if (0 != key_to)  /* send to Console window */
            fifo_put(&task_cons->fifo, 10 + 256);
        }

        if ((256 + 0x0f) == data) {
          /* TAB */
          if (0 == key_to) {
            key_to = 1;
            make_title8(win_buf, win_layer->w_size, "TASK-A", 0);
            make_title8(cons_buf, cons_layer->w_size, "Console", 1);
            cursor_c = -1;  /* don't show the cursor */
            fill_box8(win_layer->buf, win_layer->w_size, 
                COLOR8_FFFFFF, cursor_x, 28, cursor_x + 7, 43);

            fifo_put(&task_cons->fifo, 2);  /* console cursor -> ON */
          }
          else {
            key_to = 0;
            make_title8(win_buf, win_layer->w_size, "TASK-A", 1);
            make_title8(cons_buf, cons_layer->w_size, "Console", 0);
            cursor_c = COLOR8_000000; /* show the cursor */

            fifo_put(&task_cons->fifo, 3);  /* console cursor -> OFF */
          }
          layers_refresh(win_layer, 0, 0, win_layer->w_size, 21);
          layers_refresh(cons_layer, 0, 0, cons_layer->w_size, 21);
        }
        if ((256 + 0x2a) == data) /* left shift down */
          key_shift |= 1;
        if ((256 + 0x36) == data) /* right shift down */
          key_shift |= 2;
        if ((256 + 0xaa) == data) /* left shift up */
          key_shift &= ~1;
        if ((256 + 0xb6) == data) /* right shift up */
          key_shift &= ~2;
        if ((256 + 0x3a) == data) { /* CapsLock */
          key_leds ^= 4;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if ((256 + 0x45) == data) { /* NumLock */
          key_leds ^= 2;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if ((256 + 0x46) == data) { /* ScrollLock */
          key_leds ^= 1;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if (((256 + 0x3e) == data) 
            && (0 != key_shift) 
            && (0 != task_cons->tss.ss0)) {
          /* Shift + F4 force to stop user application */
          console = (console_t*)*((int*)0x0fec);
          console_putstr0(console, "\nbreak(key) :\n");
          io_cli();
          task_cons->tss.eax = (int)&(task_cons->tss.esp0);
          task_cons->tss.eip = (int)asm_stop_user_app;
          io_sti();
        }
        if (((256 + 0x57) == data) && (layer_mgr->top > 2)) {
          /* F11 switch window */
          layer_updown(layer_mgr->layers_addr[1], layer_mgr->top - 1);
        }
        if ((256 + 0xfa) == data)   /* keyboard recevie data success */
          keycmd_wait = -1;
        if ((256 + 0xfe) == data) { /* keyboard recevie data failed */
          wait_kbc_sendready();
          io_out8(PORT_KEYDATA, keycmd_wait);
        }

        /* show cursor again */
        if (cursor_c >= 0) {
          fill_box8(win_layer->buf, win_layer->w_size, 
              cursor_c, cursor_x, 28, cursor_x + 7, 43);
        }
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          layer_slide(mouse_layer, mouse_x, mouse_y);

          if (0 != (mdec.state & 0x01)) {
            /* left click button down */
            if (movemode_x < 0) {
              /* down left click, move window */
              /* find the layer of mouse on */
              for (j = layer_mgr->top - 1; j > 0; --j) {
                layer = layer_mgr->layers_addr[j];
                x = mouse_x - layer->x;
                y = mouse_y - layer->y;
                if (0 <= x && x < layer->w_size 
                    && 0 <= y && y < layer->h_size) {
                  if (layer->buf[y * layer->w_size + x] != layer->alpha) {
                    layer_updown(layer, layer_mgr->top - 1);
                    if (3 <= x 
                        && x < layer->w_size - 3 && 3 <= y && y < 21) {
                      movemode_x = mouse_x;
                      movemode_y = mouse_y;
                    }
                    if (layer->w_size - 21 <= x && x < layer->w_size - 5 
                        && 5 <= y && y < 19) {
                      /* click close button of the window */
                      if (0 != layer->task) {
                        /* whether it's the window of application */
                        console = (console_t*)*((int*)0x0fec);
                        console_putstr0(console, "\nbreak(mouse) : \n");
                        io_cli();
                        task_cons->tss.eax = (int)&task_cons->tss.esp0;
                        task_cons->tss.eip = (int)asm_stop_user_app;
                        io_sti();
                      }
                    }
                    break;
                  }
                }
              }
            }
            else {
              /* on move mode */
              x = mouse_x - movemode_x;
              y = mouse_y - movemode_y;
              layer_slide(layer, layer->x + x, layer->y + y);
              movemode_x = mouse_x;
              movemode_y = mouse_y;
            }
          }
          else 
            movemode_x = -1;  /* return to normal mode */
        }
      }
      else if (data <= 1) { /* timer by cursor */
        if (0 != data) {
          timer_init(timer, &fifo, 0);
          if (cursor_c >= 0)
            cursor_c = COLOR8_000000;
        }
        else {
          timer_init(timer, &fifo, 1);
          if (cursor_c >= 0)
            cursor_c = COLOR8_FFFFFF;
        }
        timer_settimer(timer, 50);
        
        if (cursor_c >= 0) {
          fill_box8(win_layer->buf, win_layer->w_size, 
              cursor_c, cursor_x, 28, cursor_x + 7, 43);
          layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
        }
      }
    }
  }
}
Ejemplo n.º 4
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  char debug_info[64], keybuf[32], mousebuf[128];
  int mouse_x, mouse_y;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];

  init_gdt_idt();
  init_pic();
  io_sti();

  fifo_init(&g_keybuf, keybuf, 32);
  fifo_init(&g_mousebuf, mousebuf, 128);
  io_out8(PIC0_IMR, 0xf9);
  io_out8(PIC1_IMR, 0xef);

  init_keyboard();      /* initialize keyboard */
  enable_mouse(&mdec);  /* enabled mouse */

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  back_layer = layer_alloc(layer_mgr);
  mouse_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);
  init_mouse_cursor8(mouse_buf, 99);
  layer_slide(layer_mgr, back_layer, 0, 0);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;
  layer_slide(layer_mgr, mouse_layer, mouse_x, mouse_y);
  layer_updown(layer_mgr, back_layer, 0);
  layer_updown(layer_mgr, mouse_layer, 1);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  draw_font8_asc(back_buf, binfo->screen_x, 0, 0, 
      COLOR8_FFFFFF, debug_info);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  draw_font8_asc(back_buf, binfo->screen_x, 
      0, 32, COLOR8_FFFFFF, debug_info);

  layers_refresh(layer_mgr, back_layer, 0, 0, binfo->screen_x, 48);

  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&g_keybuf) && 0 == fifo_size(&g_mousebuf)) 
      io_stihlt();
    else {
      if (0 != fifo_size(&g_keybuf)) {
          data = fifo_get(&g_keybuf);

          io_sti();
          sprintf(debug_info, "%02X", data);
          fill_box8(back_buf, binfo->screen_x, 
            COLOR8_848484, 0, 16, 15, 31);
          draw_font8_asc(back_buf, binfo->screen_x, 
            0, 16, COLOR8_FFFFFF, debug_info);

          layers_refresh(layer_mgr, back_layer, 0, 16, 16, 32);
      }
      else if (0 != fifo_size(&g_mousebuf)) {
        data = fifo_get(&g_mousebuf);
        io_sti();

        if (0 != mouse_decode(&mdec, data)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          fill_box8(back_buf, binfo->screen_x, 
              COLOR8_848484, 32, 16, 32 + 15 * 8 - 1, 31);
          draw_font8_asc(back_buf, binfo->screen_x, 
              32, 16, COLOR8_FFFFFF, debug_info);
          layers_refresh(layer_mgr, back_layer, 32, 16, 32 + 15 * 8, 32);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          fill_box8(back_buf, binfo->screen_x, 
              COLOR8_848484, 0, 0, 79, 15);     /* hide mouse position */
          draw_font8_asc(back_buf, binfo->screen_x, 
              0, 0, COLOR8_FFFFFF, debug_info); /* show mouse position */

          layers_refresh(layer_mgr, back_layer, 0, 0, 80, 16);
          layer_slide(layer_mgr, mouse_layer, mouse_x, mouse_y);
        }
      }
    }
  }
}
Ejemplo n.º 5
0
int* 
toy_api(int edi, int esi, int ebp, 
    int esp, int ebx, int edx, int ecx, int eax)
{
  int ds_base = *((int*)0x0fe8);
  task_t* task = task_now();
  console_t* console = (console_t*)(*((int*)0x0fec));
  layer_mgr_t* layermgr = (layer_mgr_t*)(*((int*)0x0fe4));
  layer_t* layer;
  int* reg = &eax + 1;  /* address after eax */
  /*
   * force to modify value of pushad
   * reg[0] : edi, reg[1] : esi, reg[2] : ebp, reg[3] : esp 
   * reg[4] : ebx, reg[5] : edx, reg[6] : ecx, reg[7] : eax
   */

  switch (edx) {
  case 1:
    console_putchar(console, eax & 0xff, 1);
    break;
  case 2:
    console_putstr0(console, (char*)ebx + ds_base);
    break;
  case 3:
    console_putstr1(console, (char*)ebx + ds_base, ecx);
    break;
  case 4:
    return &(task->tss.esp0);
  case 5: 
    {
      layer = layer_alloc(layermgr);
      layer_setbuf(layer, (char*)ebx + ds_base, esi, edi, eax);
      make_window8((char*)ebx + ds_base, esi, edi, (char*)ecx + ds_base, 0);
      layer_slide(layer, 100, 50);
      layer_updown(layer, 3);
      reg[7] = (int)layer;
    } break;
  case 6:
    {
      layer = (layer_t*)ebx;
      draw_font8_asc(layer->buf, layer->w_size, 
          esi, edi, eax, (char*)ebp + ds_base);
      layers_refresh(layer, esi, edi, esi + ecx * 8, edi + 16);
    } break;
  case 7:
    {
      layer = (layer_t*)ebx;
      fill_box8(layer->buf, layer->w_size, ebp, eax, ecx, esi, edi);
      layers_refresh(layer, eax, ecx, esi + 1, edi + 1);
    } break;
  case 8:
    {
      mem_mgr_init((mem_mgr_t*)(ebx + ds_base));
      ecx &= 0xfffffff0;  /* unit: 16bytes */
      mem_mgr_free((mem_mgr_t*)(ebx + ds_base), eax, ecx);
    } break;
  case 9: 
    {
      ecx = (ecx + 0x0f) & 0xfffffff0;
      reg[7] = mem_mgr_alloc((mem_mgr_t*)(ebx + ds_base), ecx);
    } break;
  case 10:
    {
      ecx = (ecx + 0x0f) & 0xfffffff0;
      mem_mgr_free((mem_mgr_t*)(ebx + ds_base), eax, ecx);
    } break;
  }

  return 0;
}
Ejemplo n.º 6
0
void TaskStart(void* p_data)
{
  extern u32 _end;
  u32 bss_end = (u32)(&_end);
  BOOL ret = FALSE;
  ota_trigger_t ota_trigger = 0;
  //uio_device_t *p_dev = NULL;
  u32* pstack_pnt = NULL;
//  u8 content[5] = {' ', ' ', 'O', 'N', 0};
  u32 heap_start = 0;
    u32 cpuclk = 0;

  heap_start = ROUNDUP(bss_end,4);
  mtos_irq_init();

  hal_concerto_attach( );
  mtos_register_putchar(uart_write_byte);
  mtos_register_getchar(uart_read_byte);

  hal_module_clk_get(HAL_CPU0, &cpuclk);
  mtos_ticks_init(cpuclk);
  OS_PRINTF("\r\n====OTA TaskStart====\n");

  uart_init(0);
  uart_init(1);
  uart_set_param(0, 115200, 8, 1, 0);
  uart_set_param(1, 115200, 8, 1, 0);

  OS_PRINTF("\n OTA start \n\n");
  OS_PRINTF("\n Built at %s \n", buildSTR);
  OS_PRINTF("\n 1. mem_start[%x]\n", heap_start);
  OS_PRINTF("\n 2. system memory size[%x]\n", SYS_MEMORY_END);



  mem_mgr_init((u8 *)heap_start,
  SYS_PARTITION_SIZE);

  OS_PRINTF("\n 1. mem_start[0x%x],size=0x%x\n", heap_start,
  	SYS_PARTITION_SIZE);
  dlmem_init((void *)heap_start,
  	SYS_PARTITION_SIZE);
  mtos_mem_init(dl_malloc, dl_free);
  OS_PRINTF("init mem ok!\n");

   //init message queue
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);


#ifdef CORE_DUMP_DEBUG
  //start statistic task, MUST BE in the first task!
  mtos_stat_init();
#endif

  //create timer task
  pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STKSIZE);
  MT_ASSERT(pstack_pnt != NULL);

  ret = mtos_task_create((u8 *)"Timer",
         Task_SysTimer,
         (void *)0,
         SYS_TIMER_TASK_PRIORITY,
         pstack_pnt,
         SYS_TIMER_TASK_STKSIZE);

  MT_ASSERT(FALSE != ret);

  mtos_task_sleep(25);


  ap_init();
  
  ret  = ota_check();
  OS_PRINTF("OTA check %d\n", ota_trigger);
  //{
  //  ota_info_t otai = {0};
  //  ota_read_otai(&otai);
  //  otai.ota_tri = OTA_TRI_FORC;
  //  otai.sys_mode = SYS_DVBS;
  //  ota_write_otai(&otai);
  //}
   //p_dev = dev_find_identifier(NULL, DEV_IDT_TYPE, SYS_DEV_TYPE_UIO);
   //MT_ASSERT(NULL != p_dev);

  if(ret == FALSE)
  {
    //clear frontpanel.
    //uio_display(p_dev, "    ", 4);
    reback_to_boot();
  }
  else
  {
    //uio_display(p_dev, content, 4);
  }

  mtos_task_exit( );

}
Ejemplo n.º 7
0
void TaskStart (void *data)
{
  extern u32 _end;
  u32 bss_end = (u32)(&_end);
  BOOL ret = FALSE;
  u32 *pstack_pnt = NULL;
  u32 heap_start = 0;
 // u32 montage_auto = 0;
  u32 cpuclk = 0;

  heap_start = ROUNDUP(bss_end,4);

  mtos_irq_init();

  hal_concerto_attach( );

  mtos_register_putchar(uart_write_byte);
  mtos_register_getchar(uart_read_byte_polling);

  //mtos_ticks_init(SYS_CPU_CLOCK);
  hal_module_clk_get(HAL_CPU0, &cpuclk);
  mtos_ticks_init(cpuclk);

  gpio_mux();

  mem_mgr_partition_param_t partition_param = { 0 };
  uart_init(0);
  uart_init(1);
  //init memory manager, to the memory end
  mem_mgr_init((u8 *)heap_start, SYSTEM_MEMORY_END);

  //create system partition
  partition_param.id   = MEM_SYS_PARTITION;
  partition_param.size = SYS_PARTITION_SIZE;
  partition_param.p_addr = (u8 *)heap_start;
  partition_param.atom_size = SYS_PARTITION_ATOM;
  partition_param.user_id = SYS_MODULE_SYSTEM;
  partition_param.method_id = MEM_METHOD_NORMAL;
  ret = MEM_CREATE_PARTITION(&partition_param);
  MT_ASSERT(FALSE != ret);
  mtos_mem_init(mt_mem_malloc, mt_mem_free);

 //create timer task
  pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STK_SIZE);
  MT_ASSERT(pstack_pnt != NULL);

  ret = mtos_task_create((u8 *)"Timer",
         Task_SysTimer,
         (void *)0,
         SYS_TIMER_TASK_PRIORITY,
         pstack_pnt,
         SYS_TIMER_TASK_STK_SIZE);

  MT_ASSERT(FALSE != ret);

  // init_dual_printk();

   //init message queue  
  mtos_irq_enable(TRUE);
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);

  mtos_task_sleep(100);
  ap_init();

  mtos_task_exit();
}
Ejemplo n.º 8
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo8_t timerfifo;
  char debug_info[64], keybuf[32], mousebuf[128], timerbuf[8];
  int mouse_x, mouse_y;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;

  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&g_keybuf, keybuf, 32);
  fifo_init(&g_mousebuf, mousebuf, 128);
  init_pit(); /* initialize programmable interval timer */
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */

  fifo_init(&timerfifo, timerbuf, 8);
  set_timer(1000, &timerfifo, 1);

  init_keyboard();      /* initialize keyboard */
  enable_mouse(&mdec);  /* enabled mouse */

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  back_layer = layer_alloc(layer_mgr);
  mouse_layer = layer_alloc(layer_mgr);
  win_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  layer_setbuf(win_layer, win_buf, 160, 52, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);
  init_mouse_cursor8(mouse_buf, 99);
  make_window8(win_buf, 160, 52, "Counter");
  layer_slide(back_layer, 0, 0);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_slide(win_layer, 80, 72);
  layer_updown(back_layer, 0);
  layer_updown(win_layer, 1);
  layer_updown(mouse_layer, 2);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  draw_font8_asc(back_buf, binfo->screen_x, 0, 0, 
      COLOR8_FFFFFF, debug_info);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  draw_font8_asc(back_buf, binfo->screen_x, 
      0, 32, COLOR8_FFFFFF, debug_info);

  layers_refresh(back_layer, 0, 0, binfo->screen_x, 48);

  for ( ; ; ) {
    sprintf(debug_info, "%010d", g_timerctl.count);
    fill_box8(win_buf, 160, COLOR8_C6C6C6, 40, 28, 119, 43);
    draw_font8_asc(win_buf, 160, 40, 28, COLOR8_000000, debug_info);
    layers_refresh(win_layer, 40, 28, 120, 44);

    io_cli();
    if (0 == fifo_size(&g_keybuf) 
        && 0 == fifo_size(&g_mousebuf)
        && 0 == fifo_size(&timerfifo)) 
      io_stihlt();
    else {
      if (0 != fifo_size(&g_keybuf)) {
          data = fifo_get(&g_keybuf);

          io_sti();
          sprintf(debug_info, "%02X", data);
          fill_box8(back_buf, binfo->screen_x, 
            COLOR8_848484, 0, 16, 15, 31);
          draw_font8_asc(back_buf, binfo->screen_x, 
            0, 16, COLOR8_FFFFFF, debug_info);

          layers_refresh(back_layer, 0, 16, 16, 32);
      }
      else if (0 != fifo_size(&g_mousebuf)) {
        data = fifo_get(&g_mousebuf);
        io_sti();

        if (0 != mouse_decode(&mdec, data)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          fill_box8(back_buf, binfo->screen_x, 
              COLOR8_848484, 32, 16, 32 + 15 * 8 - 1, 31);
          draw_font8_asc(back_buf, binfo->screen_x, 
              32, 16, COLOR8_FFFFFF, debug_info);
          layers_refresh(back_layer, 32, 16, 32 + 15 * 8, 32);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          fill_box8(back_buf, binfo->screen_x, 
              COLOR8_848484, 0, 0, 79, 15);     /* hide mouse position */
          draw_font8_asc(back_buf, binfo->screen_x, 
              0, 0, COLOR8_FFFFFF, debug_info); /* show mouse position */

          layers_refresh(back_layer, 0, 0, 80, 16);
          layer_slide(mouse_layer, mouse_x, mouse_y);
        }
      }
      else if (0 != fifo_size(&timerfifo)) {
        data = fifo_get(&timerfifo);
        io_sti();

        draw_font8_asc(back_buf, binfo->screen_x, 
            0, 64, COLOR8_FFFFFF, "10[sec]");
        layers_refresh(back_layer, 0, 64, 56, 80);
      }
    }
  }
}
Ejemplo n.º 9
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo, keycmd;
  int  fifobuf[128], keycmd_buf[32];
  char debug_info[64];
  int mouse_x, mouse_y, cursor_x, cursor_c;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  layer_t* cons_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  unsigned char* cons_buf;
  static char s_keytable[0x80] = {
    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 
    0,   '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0
  };
  static char s_keytable_shift[0x80] = {
    0,   0,   '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"','~', 
    0,   '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0
  };
  task_t* task_a;
  task_t* task_cons;
  timer_t* timer;
  int key_to = 0, key_shift = 0;
  int key_leds = (binfo->leds >> 4) & 7;  /* CapsLock state */
  int keycmd_wait = -1;


  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128, 0);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */
  fifo_init(&keycmd, keycmd_buf, 32, 0);

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  task_a = task_init(mem_mgr);
  fifo.task = task_a;
  task_run(task_a, 1, 2);

  /* back layer */
  back_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);

  /* console task */
  cons_layer = layer_alloc(layer_mgr);
  cons_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 256 * 165);
  layer_setbuf(cons_layer, cons_buf, 256, 165, -1); /* transparent */
  make_window8(cons_buf, 256, 165, "Console", 0);
  make_text8(cons_layer, 8, 28, 240, 128, COLOR8_000000);
  task_cons = task_alloc();
  task_cons->tss.esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8;
  task_cons->tss.eip = (int)&console_task;
  task_cons->tss.es  = 1 * 8;
  task_cons->tss.cs  = 2 * 8;
  task_cons->tss.ss  = 1 * 8;
  task_cons->tss.ds  = 1 * 8;
  task_cons->tss.fs  = 1 * 8;
  task_cons->tss.gs  = 1 * 8;
  *((int*)(task_cons->tss.esp + 4)) = (int)cons_layer;
  task_run(task_cons, 2, 2);  /* level = 2, priority = 2 */
  
  /* window layer */
  win_layer = layer_alloc(layer_mgr);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(win_layer, win_buf, 144, 52, -1);
  make_window8(win_buf, 144, 52, "TASK-A", 1);
  make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF);
  cursor_x = 8;
  cursor_c = COLOR8_FFFFFF;
  timer = timer_alloc();
  timer_init(timer, &fifo, 1);
  timer_settimer(timer, 50);

  /* mouse layer */
  mouse_layer = layer_alloc(layer_mgr);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  init_mouse_cursor8(mouse_buf, 99);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;

  layer_slide(back_layer, 0, 0);
  layer_slide(cons_layer, 32, 4);
  layer_slide(win_layer, 64, 56);
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_updown(back_layer, 0);
  layer_updown(cons_layer, 1);
  layer_updown(win_layer, 2);
  layer_updown(mouse_layer, 3);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  drawstring_and_refresh(back_layer, 0, 0, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  drawstring_and_refresh(back_layer, 0, 32, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 40);


  fifo_put(&keycmd, KEYCMD_LED);
  fifo_put(&keycmd, key_leds);

  for ( ; ; ) {
    if (fifo_size(&keycmd) > 0 && keycmd_wait < 0) {
      /* send it when send data to keyboard controller */
      keycmd_wait = fifo_get(&keycmd);
      wait_kbc_sendready();
      io_out8(PORT_KEYDATA, keycmd_wait);
    }

    io_cli();

    if (0 == fifo_size(&fifo)) {
      task_sleep(task_a);
      io_sti();
    }
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
        sprintf(debug_info, "%02X", data - 256);
        drawstring_and_refresh(back_layer, 0, 16, 
            COLOR8_FFFFFF, COLOR8_848484, debug_info, 2);

        if (data < (256 + 0x80)) {
          /* translation character */
          if (0 == key_shift)
            debug_info[0] = s_keytable[data - 256];
          else 
            debug_info[0] = s_keytable_shift[data - 256];
        }
        else 
          debug_info[0] = 0;
        if ('A' <= debug_info[0] && debug_info[0] <= 'Z') {
          /* it's an english character */
          if ((0 == (key_leds & 4) && 0 == key_shift) 
            || (0 != (key_leds & 4) && 0 != key_shift))
            debug_info[0] += 0x20;  /* character lower ('A' -> 'a') */
        }
        if (0 != debug_info[0]) {
          /* general character */
          if (0 == key_to) {
            /* send character data to TASK-A */
            if (cursor_x < 128) {
              /* display one character and cursor move backward one */
              debug_info[1] = 0;
              drawstring_and_refresh(win_layer, cursor_x, 28, 
                  COLOR8_000000, COLOR8_FFFFFF, debug_info, 1);
              cursor_x += 8;
            }
          }
          else  /* send character data to console window */
            fifo_put(&task_cons->fifo, debug_info[0] + 256);
        }

        if ((256 + 0x0e) == data) {
          /* backspace, recover cursor by sapce, move back cursor 1 time */
          if (0 == key_to) {
            if (cursor_x > 8) {
              drawstring_and_refresh(win_layer, cursor_x, 28, 
                  COLOR8_000000, COLOR8_FFFFFF, " ", 1);
              cursor_x -= 8;
            }
          }
          else 
            fifo_put(&task_cons->fifo, 8 + 256);
        }

        if ((256 + 0x0f) == data) {
          /* TAB */
          if (0 == key_to) {
            key_to = 1;
            make_title8(win_buf, win_layer->w_size, "TASK-A", 0);
            make_title8(cons_buf, cons_layer->w_size, "Console", 1);
            cursor_c = -1;  /* don't show the cursor */
            fill_box8(win_layer->buf, win_layer->w_size, 
                COLOR8_FFFFFF, cursor_x, 28, cursor_x + 7, 43);
          }
          else {
            key_to = 0;
            make_title8(win_buf, win_layer->w_size, "TASK-A", 1);
            make_title8(cons_buf, cons_layer->w_size, "Console", 0);
            cursor_c = COLOR8_000000; /* show the cursor */
          }
          layers_refresh(win_layer, 0, 0, win_layer->w_size, 21);
          layers_refresh(cons_layer, 0, 0, cons_layer->w_size, 21);
        }
        if ((256 + 0x2a) == data) /* left shift down */
          key_shift |= 1;
        if ((256 + 0x36) == data) /* right shift down */
          key_shift |= 2;
        if ((256 + 0xaa) == data) /* left shift up */
          key_shift &= ~1;
        if ((256 + 0xb6) == data) /* right shift up */
          key_shift &= ~2;
        if ((256 + 0x3a) == data) { /* CapsLock */
          key_leds ^= 4;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if ((256 + 0x45) == data) { /* NumLock */
          key_leds ^= 2;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if ((256 + 0x46) == data) { /* ScrollLock */
          key_leds ^= 1;
          fifo_put(&keycmd, KEYCMD_LED);
          fifo_put(&keycmd, key_leds);
        }
        if ((256 + 0xfa) == data)   /* keyboard recevie data success */
          keycmd_wait = -1;
        if ((256 + 0xfe) == data) { /* keyboard recevie data failed */
          wait_kbc_sendready();
          io_out8(PORT_KEYDATA, keycmd_wait);
        }

        /* show cursor again */
        if (cursor_c >= 0) {
          fill_box8(win_layer->buf, win_layer->w_size, 
              cursor_c, cursor_x, 28, cursor_x + 7, 43);
        }
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          drawstring_and_refresh(back_layer, 32, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 15);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          drawstring_and_refresh(back_layer, 0, 0, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);
          layer_slide(mouse_layer, mouse_x, mouse_y);

          if (0 != (mdec.state & 0x01)) {
            /* down left click, move window */
            layer_slide(win_layer, mouse_x - 80, mouse_y - 8);
          }
        }
      }
      else if (data <= 1) { /* timer by cursor */
        if (0 != data) {
          timer_init(timer, &fifo, 0);
          if (cursor_c >= 0)
            cursor_c = COLOR8_000000;
        }
        else {
          timer_init(timer, &fifo, 1);
          if (cursor_c >= 0)
            cursor_c = COLOR8_FFFFFF;
        }
        timer_settimer(timer, 50);
        
        if (cursor_c >= 0) {
          fill_box8(win_layer->buf, win_layer->w_size, 
              cursor_c, cursor_x, 28, cursor_x + 7, 43);
          layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
        }
      }
    }
  }
}
Ejemplo n.º 10
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo;
  int  fifobuf[128];
  char debug_info[64];
  timer_t* timer1;
  timer_t* timer2;
  timer_t* timer3;
  int mouse_x, mouse_y;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  unsigned int count = 0;

  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */

  timer1 = timer_alloc();
  timer_init(timer1, &fifo, 10);
  timer_settimer(timer1, 1000);

  timer2 = timer_alloc();
  timer_init(timer2, &fifo, 3);
  timer_settimer(timer2, 300);

  timer3 = timer_alloc();
  timer_init(timer3, &fifo, 1);
  timer_settimer(timer3, 50);

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  back_layer = layer_alloc(layer_mgr);
  mouse_layer = layer_alloc(layer_mgr);
  win_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  layer_setbuf(win_layer, win_buf, 160, 52, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);
  init_mouse_cursor8(mouse_buf, 99);
  make_window8(win_buf, 160, 52, "Counter");
  layer_slide(back_layer, 0, 0);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_slide(win_layer, 80, 72);
  layer_updown(back_layer, 0);
  layer_updown(win_layer, 1);
  layer_updown(mouse_layer, 2);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  drawstring_and_refresh(back_layer, 0, 0, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  drawstring_and_refresh(back_layer, 0, 32, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 40);

  for ( ; ; ) {
    /*
    sprintf(debug_info, "%010d", g_timerctl.count);
    drawstring_and_refresh(win_layer, 40, 28, 
        COLOR8_000000, COLOR8_C6C6C6, debug_info, 10);
     */
    ++count;

    io_cli();
    if (0 == fifo_size(&fifo))
      io_sti();
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
          sprintf(debug_info, "%02X", data - 256);
          drawstring_and_refresh(back_layer, 0, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 2);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          drawstring_and_refresh(back_layer, 32, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 15);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          drawstring_and_refresh(back_layer, 0, 0, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);
          layer_slide(mouse_layer, mouse_x, mouse_y);
        }
      }
      else if (10 == data) {
        drawstring_and_refresh(back_layer, 0, 64, 
            COLOR8_FFFFFF, COLOR8_848484, "10[sec]", 7);

        sprintf(debug_info, "%010d", count);
        drawstring_and_refresh(win_layer, 40, 28, 
            COLOR8_000000, COLOR8_C6C6C6, debug_info, 10);
      }
      else if (3 == data) {
        drawstring_and_refresh(back_layer, 0, 80, 
            COLOR8_FFFFFF, COLOR8_848484, "03[sec]", 7);

        count = 0;
      }
      else if (1 == data) {
        timer_init(timer3, &fifo, 0);
        fill_box8(back_buf, binfo->screen_x, 
            COLOR8_FFFFFF, 8, 96, 15, 111);
        timer_settimer(timer3, 50);
        layers_refresh(back_layer, 8, 96, 16, 112);
      }
      else if (0 == data) {
        timer_init(timer3, &fifo, 1);
        fill_box8(back_buf, binfo->screen_x, 
            COLOR8_848484, 8, 96, 15, 111);
        timer_settimer(timer3, 50);
        layers_refresh(back_layer, 8, 96, 16, 112);
      }
    }
  }
}
Ejemplo n.º 11
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo;
  int  fifobuf[128];
  char debug_info[64];
  int mouse_x, mouse_y, cursor_x, cursor_c;
  int data;
  int i;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  layer_t* win_layer_b[3];
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  unsigned char* win_buf_b;
  static char s_keytable[0x54] = {
    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 
    0,   '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
  };
  task_t* task_a;
  task_t* task_b[3];
  timer_t* timer;


  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128, 0);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  task_a = task_init(mem_mgr);
  fifo.task = task_a;
  task_run(task_a, 1, 2);

  /* back layer */
  back_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);

  /* window layer b */
  for (i = 0; i < 3; ++i) {
    win_layer_b[i] = layer_alloc(layer_mgr);
    win_buf_b = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 144 * 52);
    layer_setbuf(win_layer_b[i], win_buf_b, 144, 52, -1); /* transparent */
    sprintf(debug_info, "TASK-B%d", i);
    make_window8(win_buf_b, 144, 52, debug_info, 0);
    task_b[i] = task_alloc();
    task_b[i]->tss.esp = 
      mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8;
    task_b[i]->tss.eip = (int)&task_b_main;
    task_b[i]->tss.es  = 1 * 8;
    task_b[i]->tss.cs  = 2 * 8;
    task_b[i]->tss.ss  = 1 * 8;
    task_b[i]->tss.ds  = 1 * 8;
    task_b[i]->tss.fs  = 1 * 8;
    task_b[i]->tss.gs  = 1 * 8;
    *((int*)(task_b[i]->tss.esp + 4)) = (int)win_layer_b[i];
    task_run(task_b[i], 2, i + 1);
  }
  
  /* window layer */
  win_layer = layer_alloc(layer_mgr);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(win_layer, win_buf, 144, 52, -1);
  make_window8(win_buf, 144, 52, "TASK-A", 1);
  make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF);
  cursor_x = 8;
  cursor_c = COLOR8_FFFFFF;
  timer = timer_alloc();
  timer_init(timer, &fifo, 1);
  timer_settimer(timer, 50);

  /* mouse layer */
  mouse_layer = layer_alloc(layer_mgr);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  init_mouse_cursor8(mouse_buf, 99);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;

  layer_slide(back_layer, 0, 0);
  layer_slide(win_layer_b[0], 168, 56);
  layer_slide(win_layer_b[1], 8, 116);
  layer_slide(win_layer_b[2], 168, 116);
  layer_slide(win_layer, 8, 56);
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_updown(back_layer, 0);
  layer_updown(win_layer_b[0], 1);
  layer_updown(win_layer_b[1], 2);
  layer_updown(win_layer_b[2], 3);
  layer_updown(win_layer, 4);
  layer_updown(mouse_layer, 5);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  drawstring_and_refresh(back_layer, 0, 0, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  drawstring_and_refresh(back_layer, 0, 32, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 40);


  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&fifo)) {
      task_sleep(task_a);
      io_sti();
    }
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
        sprintf(debug_info, "%02X", data - 256);
        drawstring_and_refresh(back_layer, 0, 16, 
            COLOR8_FFFFFF, COLOR8_848484, debug_info, 2);

        if (data < (256 + 0x54)) {
          if (0 != s_keytable[data - 256] && cursor_x < 128) {
            /* normal character, show 1 character, move cursor 1 time */
            debug_info[0] = s_keytable[data - 256];
            debug_info[1] = 0;
            drawstring_and_refresh(win_layer, cursor_x, 28, 
                COLOR8_000000, COLOR8_FFFFFF, debug_info, 1);
            cursor_x += 8;
          }
        }
        if ((256 + 0x0e) == data && cursor_x > 8) {
          /* backspace, recover cursor by sapce, move back cursor 1 time */
          drawstring_and_refresh(win_layer, cursor_x, 28, 
              COLOR8_000000, COLOR8_FFFFFF, " ", 1);
          cursor_x -= 8;
        }
        /* show cursor again */
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          drawstring_and_refresh(back_layer, 32, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 15);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          drawstring_and_refresh(back_layer, 0, 0, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);
          layer_slide(mouse_layer, mouse_x, mouse_y);

          if (0 != (mdec.state & 0x01)) {
            /* down left click, move window */
            layer_slide(win_layer, mouse_x - 80, mouse_y - 8);
          }
        }
      }
      else if (data <= 1) { /* timer by cursor */
        if (0 != data) {
          timer_init(timer, &fifo, 0);
          cursor_c = COLOR8_000000;
        }
        else {
          timer_init(timer, &fifo, 1);
          cursor_c = COLOR8_FFFFFF;
        }
        timer_settimer(timer, 50);
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
    }
  }
}
Ejemplo n.º 12
0
void TaskStart (void *data)
{
  extern u32 _end;
  u32 bss_end = (u32)(&_end);
  BOOL ret = FALSE;
  u32 *pstack_pnt = NULL;
  u32 heap_start = 0;
 // u32 montage_auto = 0;
  u32 cpuclk = 0;

  heap_start = ROUNDUP(bss_end,4);

  mtos_irq_init();

//  hal_warriors_attach(&hal_config);
  extern void hal_concerto_attach(void);

  hal_concerto_attach( );

  mtos_register_putchar(uart_write_byte);
  mtos_register_getchar(uart_read_byte_polling);

  //mtos_ticks_init(SYS_CPU_CLOCK);
  hal_module_clk_get(HAL_CPU0, &cpuclk);
  mtos_ticks_init(cpuclk);

  mem_mgr_partition_param_t partition_param = { 0 };//, partition2_param = { 0 };
  uart_init(0);
  uart_init(1);

  //init memory manager, to the memory end
  mem_mgr_init((u8 *)heap_start, SYSTEM_MEMORY_END);

  //create system partition
  partition_param.id   = MEM_SYS_PARTITION;
  partition_param.size = SYS_PARTITION_SIZE;
  partition_param.p_addr = (u8 *)heap_start;
  partition_param.atom_size = SYS_PARTITION_ATOM;
  partition_param.user_id = SYS_MODULE_SYSTEM;
  partition_param.method_id = MEM_METHOD_NORMAL;
  ret = MEM_CREATE_PARTITION(&partition_param);
  MT_ASSERT(FALSE != ret);
#if 0
  OS_PRINTF("\n 1. mem_start[0x%x]\n", heap_start);
  OS_PRINTF("\n 2. system memory size[%d]\n", SYSTEM_MEMORY_END);
  OS_PRINTF("SYS_PARTITION_SIZE is %x\n", SYS_PARTITION_SIZE);
  OS_PRINTF("create SYS_PARTITION111 ok!\n");

  partition2_param.id   = MEM_DMA_PARTITION;
  partition2_param.size = DMA_PARTITION_SIZE;
  partition2_param.p_addr = (u8 *)((heap_start + SYS_PARTITION_SIZE + 0x40000) | 0xa0000000);
  partition2_param.atom_size = DMA_PARTITION_ATOM;
  partition2_param.user_id = SYS_MODULE_SYSTEM;
  partition2_param.method_id = MEM_METHOD_NORMAL;

  OS_PRINTF("\n 1. mem_start[0x%x]\n", partition2_param.p_addr);
  OS_PRINTF("\n 2. system memory size[%d]\n", SYSTEM_MEMORY_END);
  OS_PRINTF("SYS_PARTITION_SIZE is 0x%x\n", DMA_PARTITION_SIZE);


  ret = MEM_CREATE_PARTITION(&partition2_param);
  MT_ASSERT(FALSE != ret);
#endif
  mtos_mem_init(mt_mem_malloc, mt_mem_free);
  #if 0
  OS_PRINTF("Now check os version!\n");
  u32 os_version = get_os_version();

  if (os_version != 0x11112222) {
    OS_PRINTF("Wrong os version, please talk with os person!\n");
  }

  OS_PRINTF("Os version pass!\n");

  if(CPU_IS_AP) {
      OS_PRINTF("AP CPU id get pass \n");
  }else{
      OS_PRINTF("cannot get right cpu id \n");
  }
  #endif
 //create timer task
  pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STK_SIZE);
  MT_ASSERT(pstack_pnt != NULL);

  ret = mtos_task_create((u8 *)"Timer",
         Task_SysTimer,
         (void *)0,
         SYS_TIMER_TASK_PRIORITY,
         pstack_pnt,
         SYS_TIMER_TASK_STK_SIZE);

  MT_ASSERT(FALSE != ret);

  // init_dual_printk();

   //init message queue
  //OS_PRINTF("start    mtos_irq_enable!!!!!!!!!!!!!!\n");
  mtos_irq_enable(TRUE);
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);


#ifdef CORE_DUMP_DEBUG
   mtos_stat_init();
#endif

   init_section();
  mtos_task_sleep(100);

   ap_init();

  mtos_task_exit();
}
Ejemplo n.º 13
0
void task_sys_init(void *p_data)
{
  BOOL ret = FALSE;
  u32 *p_pstack_pnt = NULL;
  mem_mgr_partition_param_t partition_param = { 0 };
  extern void Task_SysTimer(void *p_data);
  extern void ap_init(void);
  hal_config_t hal_config = {0};

  hal_win32_attach(&hal_config);

  //init memory manager, to the memory end
  mem_mgr_init((u8 *)get_mem_addr(), SYS_MEMORY_END);

  /* create SYS partition */
  partition_param.id   = MEM_SYS_PARTITION;
  partition_param.size = SYS_PARTITION_SIZE;
  partition_param.p_addr = (u8 *)get_mem_addr();
  partition_param.atom_size = SYS_PARTITION_ATOM;
  partition_param.user_id = SYS_MODULE_SYSTEM;
  partition_param.method_id = MEM_METHOD_NORMAL;
  ret = MEM_CREATE_PARTITION(&partition_param);
  MT_ASSERT(FALSE != ret);
  OS_PRINTF("create patition ok!\n");

  //register malloc/free function, using system partition
  mtos_mem_init(my_malloc, my_free);
  OS_PRINTF("init mem ok!\n");

  mtos_ticks_init(SYS_CPU_CLOCK);

  //init message queue
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);

  #ifdef CORE_DUMP_DEBUG
  //start statistic task, MUST BE in the first task!
  mtos_stat_init();
  #endif

  //create timer task
  p_pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STKSIZE);
  MT_ASSERT(p_pstack_pnt != NULL);

  ret = mtos_task_create((u8 *)"Timer",
    Task_SysTimer,
    (void *)0,
    SYS_TIMER_TASK_PRIORITY,
    p_pstack_pnt,
    SYS_TIMER_TASK_STKSIZE);

  MT_ASSERT(FALSE != ret);
  OS_PRINTF("create timer task ok!\n");

  mtos_task_sleep(M_TASK_SLEEP_TIME);//25
  OS_PRINTF("start ap init!\n");

  ret = ota_check();
  if(ret == TRUE)
  	{
	  ap_init();
	  OS_PRINTF("ap init ok!\n");
  	}
	else
	{
	  MT_ASSERT(0);
	}

  mtos_task_exit();
}
Ejemplo n.º 14
0
void TaskStart (void *data)
{
  extern u32 _end;
  u32 bss_end = (u32)(&_end);
  BOOL ret = FALSE;
  u32 heap_start = 0;
  u32 cpuclk = 0;

  heap_start = ROUNDUP(bss_end,4);
  mtos_irq_init();
  extern void hal_concerto_attach(void);

  hal_concerto_attach( );

  mtos_register_putchar(uart_write_byte);
  mtos_register_getchar(uart_read_byte);

  hal_module_clk_get(HAL_CPU0, &cpuclk);
  mtos_ticks_init(cpuclk);

  /* uart1 pin mux */
  gpio_mux();
  uart_init(0);
  uart_init(1);
  uart_set_param(0, 115200, 8, 1, 0);
  uart_set_param(1, 115200, 8, 1, 0);

  OS_PRINTF("\n FastLogo app start\n");
  OS_PRINTF("\n Built at %s \n", buildSTR);

  OS_PRINTF("\n 1. heap_start[0x%x]\n", heap_start);
  OS_PRINTF("\n 2. whole memory size[0x%x]\n", (WHOLE_MEM_END & 0xFFFFFFF));

  OS_PRINTF("\n 3. SYS_PARTITION_SIZE is 0x%x, GUI_RESOURCE_BUFFER_ADDR is 0x%x\n", SYS_PARTITION_SIZE, GUI_RESOURCE_BUFFER_ADDR);

  if((heap_start + SYS_PARTITION_SIZE) > (GUI_RESOURCE_BUFFER_ADDR + 0x80000000))
  {
    OS_PRINTF("system partition is overlaped %d\n", (heap_start + SYS_PARTITION_SIZE) - GUI_RESOURCE_BUFFER_ADDR - 0x80000000);
    MT_ASSERT(0);
  }
  //init memory manager, only 11M
  //mem_mgr_init((u8 *)heap_start, SYS_PARTITION_SIZE + (1 * 1024 * 1024));
  OS_PRINTF("\n 4. free mem size 0x%x address from 0x%x to 0x%x\n", 
  (GUI_RESOURCE_BUFFER_ADDR | 0x80000000) - (heap_start + SYS_PARTITION_SIZE),
  (heap_start + SYS_PARTITION_SIZE),(GUI_RESOURCE_BUFFER_ADDR | 0x80000000));


  mem_mgr_init((u8 *)heap_start,
  SYS_PARTITION_SIZE);

  OS_PRINTF("\n 5. mem_mgr_start[0x%x],size=0x%x\n", heap_start,
  	SYS_PARTITION_SIZE);
  dlmem_init((void *)heap_start,
  	SYS_PARTITION_SIZE);
  mtos_mem_init(dl_malloc, dl_free);
  OS_PRINTF("init mem ok!\n");


//enable interrupt
  mtos_irq_enable(TRUE);

  //init message queue
  ret = mtos_message_init();
  MT_ASSERT(FALSE != ret);


  ap_init();

  mtos_task_exit();
}
Ejemplo n.º 15
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo;
  int  fifobuf[128];
  char debug_info[64];
  timer_t* timer1;
  timer_t* timer2;
  timer_t* timer3;
  int mouse_x, mouse_y, cursor_x, cursor_c, task_b_esp;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  static char s_keytable[0x54] = {
    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 
    0,   '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
  };
  tss32_t tss_a, tss_b;
  segment_descriptor_t* gdt = (segment_descriptor_t*)ADR_GDT;


  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */

  set490(&fifo, 1);
  timer1 = timer_alloc();
  timer_init(timer1, &fifo, 10);
  timer_settimer(timer1, 1000);

  timer2 = timer_alloc();
  timer_init(timer2, &fifo, 3);
  timer_settimer(timer2, 300);

  timer3 = timer_alloc();
  timer_init(timer3, &fifo, 1);
  timer_settimer(timer3, 50);

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  back_layer = layer_alloc(layer_mgr);
  mouse_layer = layer_alloc(layer_mgr);
  win_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  layer_setbuf(win_layer, win_buf, 160, 52, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);
  init_mouse_cursor8(mouse_buf, 99);
  make_window8(win_buf, 160, 52, "Window");
  make_text8(win_layer, 8, 28, 144, 16, COLOR8_FFFFFF);
  cursor_x = 8;
  cursor_c = COLOR8_FFFFFF;
  layer_slide(back_layer, 0, 0);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_slide(win_layer, 80, 72);
  layer_updown(back_layer, 0);
  layer_updown(win_layer, 1);
  layer_updown(mouse_layer, 2);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  drawstring_and_refresh(back_layer, 0, 0, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  drawstring_and_refresh(back_layer, 0, 32, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 40);


  tss_a.ldtr = 0;
  tss_a.iomap = 0x40000000;
  tss_b.ldtr = 0;
  tss_b.iomap = 0x40000000;
  set_segment_descriptor(gdt + 3, 103, (int)&tss_a, AR_TSS32);
  set_segment_descriptor(gdt + 4, 103, (int)&tss_b, AR_TSS32);
  load_tr(3 * 8);
  task_b_esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8;
  tss_b.eip = (int)&task_b_main;
  tss_b.eflags = 0x00000202;  /* IF = 1 */
  tss_b.eax = 0;
  tss_b.ecx = 0;
  tss_b.edx = 0;
  tss_b.ebx = 0;
  tss_b.esp = task_b_esp;
  tss_b.ebp = 0;
  tss_b.esi = 0;
  tss_b.edi = 0;
  tss_b.es = 1 * 8;
  tss_b.cs = 2 * 8;
  tss_b.ss = 1 * 8;
  tss_b.ds = 1 * 8;
  tss_b.fs = 1 * 8;
  tss_b.gs = 1 * 8;
  *((int*)(task_b_esp + 4)) = (int)back_layer;
  mt_init();

  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&fifo))
      io_stihlt();
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
        sprintf(debug_info, "%02X", data - 256);
        drawstring_and_refresh(back_layer, 0, 16, 
            COLOR8_FFFFFF, COLOR8_848484, debug_info, 2);

        if (data < (256 + 0x54)) {
          if (0 != s_keytable[data - 256] && cursor_x < 144) {
            /* normal character, show 1 character, move cursor 1 time */
            debug_info[0] = s_keytable[data - 256];
            debug_info[1] = 0;
            drawstring_and_refresh(win_layer, cursor_x, 28, 
                COLOR8_000000, COLOR8_FFFFFF, debug_info, 1);
            cursor_x += 8;
          }
        }
        if ((256 + 0x0e) == data && cursor_x > 8) {
          /* backspace, recover cursor by sapce, move back cursor 1 time */
          drawstring_and_refresh(win_layer, cursor_x, 28, 
              COLOR8_000000, COLOR8_FFFFFF, " ", 1);
          cursor_x -= 8;
        }
        /* show cursor again */
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          drawstring_and_refresh(back_layer, 32, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 15);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          drawstring_and_refresh(back_layer, 0, 0, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);
          layer_slide(mouse_layer, mouse_x, mouse_y);

          if (0 != (mdec.state & 0x01)) {
            /* down left click, move window */
            layer_slide(win_layer, mouse_x - 80, mouse_y - 8);
          }
        }
      }
      else if (10 == data) {
        drawstring_and_refresh(back_layer, 0, 64, 
            COLOR8_FFFFFF, COLOR8_848484, "10[sec]", 7);
      }
      else if (3 == data) {
        drawstring_and_refresh(back_layer, 0, 80, 
            COLOR8_FFFFFF, COLOR8_848484, "03[sec]", 7);
      }
      else if (data <= 1) { /* timer by cursor */
        if (0 != data) {
          timer_init(timer3, &fifo, 0);
          cursor_c = COLOR8_000000;
        }
        else {
          timer_init(timer3, &fifo, 1);
          cursor_c = COLOR8_FFFFFF;
        }
        timer_settimer(timer3, 50);
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
    }
  }
}