int main(uint32_t magic, struct mbi *mbi) { if (magic == MBI_MAGIC) { if ((mbi->flags & MBI_FLAG_CMDLINE) != 0) parse_cmdline((const char *)mbi->cmdline); } else { printf("Not loaded by Multiboot-compliant loader. Bye.\n"); return 1; } printf("\nBender %s\n", version_str); printf("Blame Julian Stecklina <*****@*****.**> for bugs.\n\n"); printf("Looking for serial controllers on the PCI bus...\n"); struct pci_device serial_ctrl; printf("Promisc is %s.\n", be_promisc ? "on" : "off"); if (pci_find_device_by_class(PCI_CLASS_SIMPLE_COMM, be_promisc ? PCI_SUBCLASS_ANY : PCI_SUBCLASS_SERIAL_CTRL, &serial_ctrl)) { printf(" found at %x.\n", serial_ctrl.cfg_address); } else { printf(" none found.\n"); goto boot_next; } uint16_t iobase = 0; for (unsigned bar_no = 0; bar_no < 6; bar_no++) { uint32_t bar = pci_cfg_read_uint32(&serial_ctrl, PCI_CFG_BAR0 + 4*bar_no); if ((bar & PCI_BAR_TYPE_MASK) == PCI_BAR_TYPE_IO) { iobase = bar & PCI_BAR_IO_MASK; break; } } iobase = apply_quirks(&serial_ctrl, iobase); uint16_t *com0_port = (uint16_t *)(get_bios_data_area()); uint16_t *equipment_word = &get_bios_data_area()->equipment; if (iobase != 0) { printf("Patching BDA with I/O port 0x%x.\n", iobase); *com0_port = iobase; *equipment_word = (*equipment_word & ~(0xF << 9)) | (1 << 9); /* One COM port available */ } else { printf("I/O ports for controller not found.\n"); } boot_next: if (serial_ports(get_bios_data_area())) serial_init(); printf("Bender: Hello World.\n"); return start_module(mbi, false, phys_max_relocate); }
BROKER_RESULT Broker_AddModule(BROKER_HANDLE broker, const MODULE* module) { BROKER_RESULT result; /*Codes_SRS_BROKER_99_013: [If `broker` or `module` is NULL the function shall return BROKER_INVALIDARG.]*/ if (broker == NULL || module == NULL) { result = BROKER_INVALIDARG; LogError("invalid parameter (NULL)."); } /*Codes_SRS_BROKER_99_014: [If `module_handle` or `module_apis` are `NULL` the function shall return `BROKER_INVALIDARG`.]*/ else if (module->module_apis == NULL || module->module_handle == NULL) { result = BROKER_INVALIDARG; LogError("invalid parameter (NULL)."); } else { BROKER_MODULEINFO* module_info = (BROKER_MODULEINFO*)malloc(sizeof(BROKER_MODULEINFO)); if (module_info == NULL) { LogError("Allocate module info failed"); result = BROKER_ERROR; } else { if (init_module(module_info, module) != BROKER_OK) { /*Codes_SRS_BROKER_13_047: [This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise.]*/ LogError("start_module failed"); free(module_info->module); free(module_info); result = BROKER_ERROR; } else { /*Codes_SRS_BROKER_13_039: [This function shall acquire the lock on BROKER_HANDLE_DATA::modules_lock.]*/ BROKER_HANDLE_DATA* broker_data = (BROKER_HANDLE_DATA*)broker; if (Lock(broker_data->modules_lock) != LOCK_OK) { /*Codes_SRS_BROKER_13_047: [This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise.]*/ LogError("Lock on broker_data->modules_lock failed"); deinit_module(module_info); free(module_info); result = BROKER_ERROR; } else { /*Codes_SRS_BROKER_13_045: [Broker_AddModule shall append the new instance of BROKER_MODULEINFO to BROKER_HANDLE_DATA::modules.]*/ LIST_ITEM_HANDLE moduleListItem = singlylinkedlist_add(broker_data->modules, module_info); if (moduleListItem == NULL) { /*Codes_SRS_BROKER_13_047: [This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise.]*/ LogError("singlylinkedlist_add failed"); deinit_module(module_info); free(module_info); result = BROKER_ERROR; } else { if (start_module(module_info, broker_data->url) != BROKER_OK) { LogError("start_module failed"); deinit_module(module_info); singlylinkedlist_remove(broker_data->modules, moduleListItem); free(module_info); result = BROKER_ERROR; } else { /*Codes_SRS_BROKER_13_047: [This function shall return BROKER_ERROR if an underlying API call to the platform causes an error or BROKER_OK otherwise.]*/ result = BROKER_OK; } } /*Codes_SRS_BROKER_13_046: [This function shall release the lock on BROKER_HANDLE_DATA::modules_lock.]*/ Unlock(broker_data->modules_lock); } } } } return result; }