/** * The server entry point. */ void clock_init(void) { int r = 0; void *device; okl4_env_segment_t *timer_seg; /* * Setup resources for driver init - this should probably be weaved */ resources[r].type = MEMORY_RESOURCE; timer_seg = okl4_env_get_segment("MAIN_TIMER_MEM0"); if (timer_seg == NULL) { printf("couldn't find timer memory mapping\n"); return; } resources[r++].resource.mem = (mem_space_t) timer_seg->virt_addr; struct okl4_env_device_irqs * timer_irqs = (struct okl4_env_device_irqs *)okl4_env_get("TIMER_DEV_IRQ_LIST"); if (timer_irqs == NULL) { printf("couldn't find timer irq list\n"); return; } /* Nano can only handle one interrupt anyway */ resources[r].type = INTERRUPT_RESOURCE; resources[r++].resource.interrupt = timer_irqs->irqs[0]; CLOCK_IRQ = timer_irqs->irqs[0]; for (/*none*/; r < 8; r++) { resources[r].type = NO_RESOURCE; } /* * Allocate memory for the device */ device = malloc(TIMER_DRIVER.size); if (device == NULL) { free(device); return; } /* Initialise the device state */ { timer_device.resources = resources; } /* Create and enable the device */ timer_device.di = setup_device_instance(&TIMER_DRIVER, device); device_setup(timer_device.di, timer_device.resources); timer_device.ti = (struct timer_interface *)device_get_interface(timer_device.di, 0); device_enable(timer_device.di); timer_device.frequency = timer_get_tick_frequency(timer_device.ti); }
/*********************************************************** * Name: * main * Description: * Start Function of the Kernel * Parameter: * ReturnValue: * EXIT_SUCCESS * **********************************************************/ void main() { /* Global Descriptor Table setup */ gdt_setup(); /* Interrupt Descriptor Table setup */ idt_setup(); /* Setup Interrupts */ irq_setup(); /* Setup Empty Devices */ device_setup(); /* Initialize Video Device -> Device does not send Interrupts */ initializeDevice(0,(char *)0xB8000,DEVICE_VIDEO,NULL,IRQ_EMPTY); /* Initialize Keyboard Handler */ initializeDevice(1,NULL,DEVICE_KEYBOARD,irq_keyboard_handler,IRQ_KEYBOARD); /* set Video Device for Console */ setVideoDevice(getDevice(0,DEVICE_VIDEO)); /* Initialize the Character Buffer */ initLineBuffer(); /* Clear Screen on Video Device */ clear_screen(); /* Printing OS Headers */ printf("\t\t-------------------------\n", C437_GREEN); printf("\t\tWELLCOME TO "OS_NAME"\n", C437_GREEN); printf("\t\t-------------------------\n", C437_GREEN); printf("\t\t"OS_NAME" version "OS_VERSION", Copyright (C) 2012 Simon Sommer\n", C437_CYAN); printf("\t\t"OS_NAME" comes with ABSOLUTELY NO WARRANTY.\n", C437_CYAN); printf("\t\tThis is free software, and you are\n", C437_CYAN); printf("\t\twelcome to redistribute it under certain conditions.\n", C437_CYAN); /* Enable Full 4GB Memory */ enableA20(); printf("\t\tA20 GATE ACTIVATED\n", C437_GREEN); /* Gives Feedback of previus done Tasks */ printf("\t\tGDT SETUP DONE\n", C437_GREEN); printf("\t\tIDT SETUP DONE\n", C437_GREEN); printf("\t\tIRQ SETUP DONE\n", C437_GREEN); /* Enable Iterrupts */ __asm__ __volatile__ ("sti"); printf("\t\tINTERRUPTS ENABLED\n", C437_GREEN); while(1); /* TODO: Malloc and Free Debug and Final Test */ }
static dev_node_t *serial_attach(dev_locator_t *loc) { u_int io; u_char irq; int line; struct serial_struct serial; struct pci_dev *pdev; dev_node_t *node; MOD_INC_USE_COUNT; if (loc->bus != LOC_PCI) goto err_out; pdev = pci_find_slot (loc->b.pci.bus, loc->b.pci.devfn); if (!pdev) goto err_out; if (pci_enable_device(pdev)) goto err_out; printk(KERN_INFO "serial_attach(bus %d, fn %d)\n", pdev->bus->number, pdev->devfn); io = pci_resource_start (pdev, 0); irq = pdev->irq; if (!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) { printk(KERN_NOTICE "serial_cb: PCI base address 0 is not IO\n"); goto err_out; } device_setup(pdev, io); memset(&serial, 0, sizeof(serial)); serial.port = io; serial.irq = irq; serial.flags = ASYNC_SKIP_TEST | ASYNC_SHARE_IRQ; /* Some devices seem to need extra time */ __set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout(HZ/50); line = register_serial(&serial); if (line < 0) { printk(KERN_NOTICE "serial_cb: register_serial() at 0x%04x, " "irq %d failed\n", serial.port, serial.irq); goto err_out; } node = kmalloc(sizeof(dev_node_t), GFP_KERNEL); if (!node) goto err_out_unregister; sprintf(node->dev_name, "ttyS%d", line); node->major = TTY_MAJOR; node->minor = 0x40 + line; node->next = NULL; return node; err_out_unregister: unregister_serial(line); err_out: MOD_DEC_USE_COUNT; return NULL; }
static bool _io_init(spi_device_t *dev, struct gpio_pin *cs) { do { if (!gpio_configure(cs)) break; gpio_set(cs); if (!device_open(dev)) break; device_setup(dev, SPI_DEVICE_PARAMETER_CLOCK, 1000000UL); device_setup(dev, SPI_DEVICE_PARAMETER_BITS, SPI_8_BIT); device_setup(dev, SPI_DEVICE_PARAMETER_PHASE, SPI_PHASE_0); device_setup(dev, SPI_DEVICE_PARAMETER_POLARITY, SPI_POLARITY_0); device_setup(dev, SPI_DEVICE_PARAMETER_MODE, SPI_MODE_MASTER); device_setup(dev, SPI_DEVICE_PARAMETER_DIRECTION, SPI_DIRECTION_1LINE); if (!device_configure(dev)) break; return true; } while (0); return false; }
void start_kernel(void) { seg_t base, end; /* We set the idle task as #0, and init_task() will be task #1 */ sched_init(); /* This block of functions don't need console */ setup_arch(&base, &end); mm_init(base, end); buffer_init(); inode_init(); init_IRQ(); tty_init(); init_console(); #if (CONFIG_BOGOMIPS == 0) calibrate_delay(); #endif device_setup(); #ifdef CONFIG_SOCKET sock_init(); #endif fs_init(); mm_stat(base, end); printk("ELKS version %s\n", system_utsname.release); kfork_proc(init_task); wake_up_process(&task[1]); /* * We are now the idle task. We won't run unless no other process can run. */ while (1) { schedule(); #ifdef CONFIG_IDLE_HALT idle_halt (); #endif } }
void start_kernel(void) { seg_t base, end; /* We set the scheduler up as task #0, and this as task #1 */ setup_arch(&base, &end); mm_init(base, end); init_IRQ(); init_console(); #if 0 calibrate_delay(); #endif setup_mm(); /* Architecture specifics */ tty_init(); buffer_init(); #ifdef CONFIG_SOCKET sock_init(); #endif device_setup(); inode_init(); fs_init(); sched_init(); printk("ELKS version %s\n", system_utsname.release); task[0].t_kstackm = KSTACK_MAGIC; task[0].next_run = task[0].prev_run = &task[0]; kfork_proc(&task[1], init_task); /* * We are now the idle task. We won't run unless no other process can run. */ while (1){ schedule(); } }
///////////////////////////////////////////////////////////////////////////// // Main-Funktion ///////////////////////////////////////////////////////////////////////////// int main(int argc, const char *argv[]) { // Initializations // // first some basic hardware infrastructure timer_init(); // Timer Interrupt initialisieren led_init(); provider_init(); // needs to be in the beginning, as other // modules like serial register here term_init(); // does not need endpoint/provider yet // but can take up to a buffer of text #ifdef __AVR__ stdout = &term_stdout; // redirect stdout #else device_setup(argc, argv); #endif // server communication uarthw_init(); // first hardware provider_t *serial = serial_init(); // then logic layer // now prepare for terminal etc // (note: in the future the assign parameter could be used // to distinguish different UARTs for example) void *epdata = serial->prov_assign(NAMEINFO_UNUSED_DRIVE, NULL); term_endpoint.provider = serial; term_endpoint.provdata = epdata; // and set as default provider_set_default(serial, epdata); // debug output via "terminal" term_set_endpoint(&term_endpoint); // init file handling (active open calls) file_init(); // buffer structures buffer_init(); // direct buffer handling direct_init(); // relfile handling relfile_init(); // init main channel handling channel_init(); // before we init any busses, we init the runtime config code // note it gets the provider to register a listener for X command line params rtconfig_init(&term_endpoint); // bus init // first the general bus (with bus counter) bus_init(); // this call initializes the device-specific hardware // e.g. IEEE488 and IEC busses on xs1541, plus SD card on petSD and so on // it also handles the interrupt initialization if necessary device_init(); #ifdef HAS_EEPROM // read bus-independent settings from non volatile memory nv_restore_common_config(); #endif // enable interrupts enable_interrupts(); // sync with the server serial_sync(); // pull in command line config options from server // also send directory charset rtconfig_pullconfig(argc, argv); #ifdef USE_FAT // register fat provider provider_register("FAT", &fat_provider); //provider_assign(0, "FAT", "/"); // might be overwritten when fetching X-commands //provider_assign(1, "FAT", "/"); // from the server, but useful for standalone-mode #endif // show our version... ListVersion(); // ... and some system info term_printf((" %u Bytes free"), BytesFree()); term_printf((", %d kHz"), FreqKHz()); #ifdef __AVR__ fuse_info(); #endif term_putcrlf(); term_putcrlf(); while (1) // Mainloop-Begin { // keep data flowing on the serial line main_delay(); if (!is_locked) device_loop(); // send out log messages term_flush(); } }
/* * Ok, the machine is now initialized. None of the devices * have been touched yet, but the CPU subsystem is up and * running, and memory and process management works. * * Now we can finally start doing some real work.. */ static void __init do_basic_setup(void) { #ifdef CONFIG_BLK_DEV_INITRD int real_root_mountflags; #endif /* * Tell the world that we're going to be the grim * reaper of innocent orphaned children. * * We don't want people to have to make incorrect * assumptions about where in the task array this * can be found. */ child_reaper = current; #if defined(CONFIG_MTRR) /* Do this after SMP initialization */ /* * We should probably create some architecture-dependent "fixup after * everything is up" style function where this would belong better * than in init/main.c.. */ mtrr_init(); #endif #ifdef CONFIG_SYSCTL sysctl_init(); #endif /* * Ok, at this point all CPU's should be initialized, so * we can start looking into devices.. */ #ifdef CONFIG_PCI pci_init(); #endif #ifdef CONFIG_SBUS sbus_init(); #endif #if defined(CONFIG_PPC) powermac_init(); #endif #ifdef CONFIG_MCA mca_init(); #endif #ifdef CONFIG_ARCH_ACORN ecard_init(); #endif #ifdef CONFIG_ZORRO zorro_init(); #endif #ifdef CONFIG_DIO dio_init(); #endif #ifdef CONFIG_TC tc_init(); #endif #ifdef CONFIG_PS2 ps2_dev_init(); /* PlayStation 2 devices */ #endif /* Networking initialization needs a process context */ sock_init(); /* Launch bdflush from here, instead of the old syscall way. */ kernel_thread(bdflush, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); /* Start the background pageout daemon. */ kswapd_setup(); kernel_thread(kswapd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); #if CONFIG_AP1000 /* Start the async paging daemon. */ { extern int asyncd(void *); kernel_thread(asyncd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); } #endif #ifdef CONFIG_BLK_DEV_INITRD real_root_dev = ROOT_DEV; real_root_mountflags = root_mountflags; if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY; else mount_initrd =0; #endif /* Set up devices .. */ device_setup(); /* .. executable formats .. */ binfmt_setup(); /* .. filesystems .. */ filesystem_setup(); /* Mount the root filesystem.. */ mount_root(); #ifdef CONFIG_UMSDOS_FS { /* When mounting a umsdos fs as root, we detect the pseudo_root (/linux) and initialise it here. pseudo_root is defined in fs/umsdos/inode.c */ extern struct inode *pseudo_root; if (pseudo_root != NULL){ current->fs->root = pseudo_root->i_sb->s_root; current->fs->pwd = pseudo_root->i_sb->s_root; } } #endif #ifdef CONFIG_BLK_DEV_INITRD root_mountflags = real_root_mountflags; if (mount_initrd && ROOT_DEV != real_root_dev && MAJOR(ROOT_DEV) == RAMDISK_MAJOR && MINOR(ROOT_DEV) == 0) { int error; int i, pid; pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD); if (pid>0) while (pid != wait(&i)); if (MAJOR(real_root_dev) != RAMDISK_MAJOR || MINOR(real_root_dev) != 0) { error = change_root(real_root_dev,"/initrd"); if (error) printk(KERN_ERR "Change root to /initrd: " "error %d\n",error); } } #endif }