// Initialize the GDT void gdt_init() { // Tasks setup for (int i = 0; i < tasks_nb; i++) setup_task(i); // Set the address and the size of the GDT in the pointer gdt_ptr.limit = sizeof(gdt); gdt_ptr.base = (uint32_t) &gdt; // Initializing the three segment descriptors in the GDT : NULL, code segment, data segment gdt[0] = null_segment(); gdt[1] = code_segment(0, 1048575, DPL_KERNEL); gdt[2] = data_segment(0, 1048575, DPL_KERNEL); // gdt[3] : entry for initial kernel TSS (CPU state of first task saved there) static uint8_t initial_tss_kernel_stack[65536]; // 64KB of stack static tss_t initial_tss; gdt[3] = gdt_make_tss(&initial_tss, DPL_KERNEL); memset(&initial_tss, 0, sizeof(tss_t)); initial_tss.ss0 = GDT_KERNEL_DATA_SELECTOR; initial_tss.esp0 = ((uint32_t) initial_tss_kernel_stack) + sizeof(initial_tss_kernel_stack); // Load the GDT gdt_flush(&gdt_ptr); // Load the task register to point to the initial TSS selector load_task_register(gdt_entry_to_selector(&gdt[3])); // Confirmation message set_text_color(LIGHT_GREEN); printf("OK\n"); set_text_color(WHITE); }
/* Note: this is not the first ui function to be called. * Display modes are registered prior to this * function being called. * In fact, all display modes must be registered * before this function is called. */ task_t *ui_task_create(u8 start_mode) { #if 0 /* These modes are not enabled by default */ set_mode_disable_bit_cb(MODE_OILPRES); set_mode_disable_bit_cb(MODE_EGT_INSTANT); set_mode_disable_bit_cb(MODE_EGT_PEAK); #endif if (start_mode == MODE_MODE_SELECT) { current.mnum = MODE_MODE_SELECT; display_modes[MODE_MODE_SELECT].displayfunc = mode_select_display_func; ui_in_config_flag = 1; do_config_word(0); } else { load_configuration_words(); if (start_mode == MODE_ATMOSPHERIC) { /* Do not validate if we are starting up in atmospheric mode. * Even if it is disabled it should be displayed after measurement. */ current.mnum = start_mode; } else { current.mnum = validate_mode(start_mode); } } ui_display_callback(NULL); return setup_task(&ui_taskinfo, TASK_ID_UI, ui_task, ui_mailbox_buf, sizeof(ui_mailbox_buf)); }
task_t *i2c_task_create() { /* Enable internal pullups for SDA and SCL */ DDRD &= (~3); /* D0/D1 inputs (this is overriddedn with TWEN) */ PORTD |= 3; /* D0/D1 pulled up */ TWSR = 0; /* no prescaler */ TWBR = 72; /* = 100kHz @ 16MHz core */ return setup_task(&i2c_taskinfo, TASK_ID_I2C, i2c_task, i2c_mailbox_buf, sizeof(i2c_mailbox_buf)); }
/* called by main */ task_t* comms_task_create() { /* Configure the baud rate. * Should move this to comms_avr.c */ UBRR0L = (uint8_t)(CPU_FREQ/(UART_BAUD_RATE*16L)-1); UBRR0H = (CPU_FREQ/(UART_BAUD_RATE*16L)-1) >> 8; UCSR0A = 0x0; UCSR0C = _BV(UCSZ01)|_BV(UCSZ00); UCSR0B = _BV(TXEN0)|_BV(RXEN0)|_BV(RXCIE0); return setup_task(&comms_taskinfo, TASK_ID_COMMS, comms_task, comms_mailbox_buf, sizeof(comms_mailbox_buf)); }
task_t *onewire_task_create() { return setup_task(&ow_taskinfo, TASK_ID_ONEWIRE, ow_task, ow_mailbox_buf, sizeof(ow_mailbox_buf)); }
void start_kernel(void) { char str[] = "C FUNCTION START!"; /* * ARCHITECTURE DEPENDENT INITIALIZATIONS */ /* screen - message display */ init_screen(); caos_printf("%s\n", str); /* memory manager */ setup_memory(); /* exception & interrupt */ init_idt(); set_idtr(); /* device & IRQ */ init_char_dev(); keyboard_init(); init_timer(); /* scheduling */ init_scheduler(); /* task management */ setup_task(); init_cpu_tss(); /* after task setup, start scheduler */ start_scheduler(); /*************************************************/ /* * ARCHITECTURE INDEPENDENT PROCESSING */ if (create_task(init, "init") < 0) caos_printf("Create Init fail..\n"); if (create_task(user1, "user1") < 0) caos_printf("Create user1 fail..\n"); if (create_task(user2, "user2") < 0) caos_printf("Create user2 fail..\n"); caos_printf("CaOS KERNEL END!!\n"); /* execute user mode task */ start_init(); while (1); }