2 * main.c - main routine of neug
5 * Copyright (C) 2011, 2012, 2013 Free Software Initiative of Japan
6 * Author: NIIBE Yutaka <gniibe@fsij.org>
8 * This file is a part of NeuG, a True Random Number Generator
11 * NeuG is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * NeuG is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 #include "stm32f103.h"
38 chopstx_mutex_t usb_mtx;
39 chopstx_cond_t cnd_usb;
41 extern uint8_t __process0_stack_end__;
42 static chopstx_t main_thd = (uint32_t)(&__process0_stack_end__ - 60);
44 #define ENDP0_RXADDR (0x40)
45 #define ENDP0_TXADDR (0x80)
46 #define ENDP1_TXADDR (0xc0)
47 #define ENDP2_TXADDR (0x100)
48 #define ENDP3_RXADDR (0x140)
50 #define USB_CDC_REQ_SET_LINE_CODING 0x20
51 #define USB_CDC_REQ_GET_LINE_CODING 0x21
52 #define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
53 #define USB_CDC_REQ_SEND_BREAK 0x23
55 /* USB Device Descriptor */
56 static const uint8_t vcom_device_desc[18] = {
58 USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
59 0x10, 0x01, /* bcdUSB = 1.1 */
60 0x02, /* bDeviceClass (CDC). */
61 0x00, /* bDeviceSubClass. */
62 0x00, /* bDeviceProtocol. */
63 0x40, /* bMaxPacketSize. */
64 #include "usb-vid-pid-ver.c.inc"
65 1, /* iManufacturer. */
67 3, /* iSerialNumber. */
68 1 /* bNumConfigurations. */
71 /* Configuration Descriptor tree for a CDC.*/
72 static const uint8_t vcom_configuration_desc[67] = {
74 USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
75 /* Configuration Descriptor.*/
76 67, 0x00, /* wTotalLength. */
77 0x02, /* bNumInterfaces. */
78 0x01, /* bConfigurationValue. */
79 0, /* iConfiguration. */
80 0x80, /* bmAttributes (bus powered). */
81 50, /* bMaxPower (100mA). */
82 /* Interface Descriptor.*/
84 USB_INTERFACE_DESCRIPTOR_TYPE,
85 0x00, /* bInterfaceNumber. */
86 0x00, /* bAlternateSetting. */
87 0x01, /* bNumEndpoints. */
88 0x02, /* bInterfaceClass (Communications Interface Class,
90 0x02, /* bInterfaceSubClass (Abstract Control Model, CDC
92 0x01, /* bInterfaceProtocol (AT commands, CDC section
95 /* Header Functional Descriptor (CDC section 5.2.3).*/
97 0x24, /* bDescriptorType (CS_INTERFACE). */
98 0x00, /* bDescriptorSubtype (Header Functional Descriptor). */
99 0x10, 0x01, /* bcdCDC. */
100 /* Call Management Functional Descriptor. */
101 5, /* bFunctionLength. */
102 0x24, /* bDescriptorType (CS_INTERFACE). */
103 0x01, /* bDescriptorSubtype (Call Management Functional
105 0x03, /* bmCapabilities (D0+D1). */
106 0x01, /* bDataInterface. */
107 /* ACM Functional Descriptor.*/
108 4, /* bFunctionLength. */
109 0x24, /* bDescriptorType (CS_INTERFACE). */
110 0x02, /* bDescriptorSubtype (Abstract Control Management
112 0x02, /* bmCapabilities. */
113 /* Union Functional Descriptor.*/
114 5, /* bFunctionLength. */
115 0x24, /* bDescriptorType (CS_INTERFACE). */
116 0x06, /* bDescriptorSubtype (Union Functional
118 0x00, /* bMasterInterface (Communication Class
120 0x01, /* bSlaveInterface0 (Data Class Interface). */
121 /* Endpoint 2 Descriptor.*/
123 USB_ENDPOINT_DESCRIPTOR_TYPE,
124 ENDP2|0x80, /* bEndpointAddress. */
125 0x03, /* bmAttributes (Interrupt). */
126 0x08, 0x00, /* wMaxPacketSize. */
127 0xFF, /* bInterval. */
128 /* Interface Descriptor.*/
130 USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
131 0x01, /* bInterfaceNumber. */
132 0x00, /* bAlternateSetting. */
133 0x02, /* bNumEndpoints. */
134 0x0A, /* bInterfaceClass (Data Class Interface, CDC section 4.5). */
135 0x00, /* bInterfaceSubClass (CDC section 4.6). */
136 0x00, /* bInterfaceProtocol (CDC section 4.7). */
137 0x00, /* iInterface. */
138 /* Endpoint 3 Descriptor.*/
140 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
141 ENDP3, /* bEndpointAddress. */
142 0x02, /* bmAttributes (Bulk). */
143 0x40, 0x00, /* wMaxPacketSize. */
144 0x00, /* bInterval. */
145 /* Endpoint 1 Descriptor.*/
147 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
148 ENDP1|0x80, /* bEndpointAddress. */
149 0x02, /* bmAttributes (Bulk). */
150 0x40, 0x00, /* wMaxPacketSize. */
151 0x00 /* bInterval. */
156 * U.S. English language identifier.
158 static const uint8_t vcom_string0[4] = {
160 USB_STRING_DESCRIPTOR_TYPE,
161 0x09, 0x04 /* LangID = 0x0409: US-English */
164 #define USB_STRINGS_FOR_NEUG 1
165 #include "usb-strings.c.inc"
168 * Serial Number string. NOTE: This does not have CONST qualifier.
170 static uint8_t vcom_string3[28] = {
172 USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType. */
173 '0', 0, '.', 0, '0', 0, '6', 0, /* Version number of NeuG. */
175 0, 0, 0, 0, /* Filled by Unique device ID. */
182 #define NUM_INTERFACES 2
184 uint32_t bDeviceState = UNCONNECTED; /* USB device status */
187 usb_cb_device_reset (void)
189 /* Set DEVICE as not configured */
190 usb_lld_set_configuration (0);
192 /* Current Feature initialization */
193 usb_lld_set_feature (vcom_configuration_desc[7]);
197 /* Initialize Endpoint 0 */
198 usb_lld_setup_endpoint (ENDP0, EP_CONTROL, 0, ENDP0_RXADDR, ENDP0_TXADDR, 64);
201 extern uint8_t _regnual_start, __heap_end__;
203 static const uint8_t *const mem_info[] = { &_regnual_start, &__heap_end__, };
205 /* USB vendor requests to control pipe */
206 #define USB_FSIJ_MEMINFO 0
207 #define USB_FSIJ_DOWNLOAD 1
208 #define USB_FSIJ_EXEC 2
209 #define USB_NEUG_GET_INFO 254
210 #define USB_NEUG_EXIT 255 /* Ask to exit and to receive reGNUal */
213 FSIJ_DEVICE_RUNNING = 0,
215 FSIJ_DEVICE_EXEC_REQUESTED,
217 FSIJ_DEVICE_NEUG_EXIT_REQUESTED = 255
220 static uint8_t fsij_device_state = FSIJ_DEVICE_RUNNING;
222 static uint32_t rbit (uint32_t v)
226 asm ("rbit %0, %1" : "=r" (r) : "r" (v));
230 /* After calling this function, CRC module remain enabled. */
231 static int download_check_crc32 (const uint32_t *end_p)
233 uint32_t crc32 = *end_p;
236 RCC->AHBENR |= RCC_AHBENR_CRCEN;
237 CRC->CR = CRC_CR_RESET;
239 for (p = (const uint32_t *)&_regnual_start; p < end_p; p++)
242 if ((rbit (CRC->DR) ^ crc32) == 0xffffffff)
245 return USB_UNSUPPORT;
249 usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value,
250 uint16_t index, uint16_t len)
252 uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
254 if (type_rcp == (VENDOR_REQUEST | DEVICE_RECIPIENT)
255 && USB_SETUP_SET (req) && len == 0)
257 if (req_no == USB_FSIJ_EXEC)
259 if (fsij_device_state != FSIJ_DEVICE_EXITED)
262 (void)value; (void)index;
263 usb_lld_prepare_shutdown (); /* No further USB communication */
264 fsij_device_state = FSIJ_DEVICE_EXEC_REQUESTED;
266 else if (req_no == USB_NEUG_EXIT)
268 /* Force exit from the main loop. */
269 chopstx_mutex_lock (&usb_mtx);
270 chopstx_cond_signal (&cnd_usb);
271 chopstx_mutex_unlock (&usb_mtx);
284 static struct line_coding line_coding = {
285 115200, /* baud rate: 115200 */
286 0x00, /* stop bits: 1 */
287 0x00, /* parity: none */
291 static uint8_t connected;
294 vcom_port_data_setup (uint8_t req, uint8_t req_no, uint16_t value)
296 if (USB_SETUP_GET (req))
298 if (req_no == USB_CDC_REQ_GET_LINE_CODING)
300 usb_lld_set_data_to_send (&line_coding, sizeof(line_coding));
304 else /* USB_SETUP_SET (req) */
306 if (req_no == USB_CDC_REQ_SET_LINE_CODING)
308 usb_lld_set_data_to_recv (&line_coding, sizeof(line_coding));
311 else if (req_no == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
313 uint8_t connected_saved = connected;
328 chopstx_mutex_lock (&usb_mtx);
329 if (connected != connected_saved)
330 chopstx_cond_signal (&cnd_usb);
331 chopstx_mutex_unlock (&usb_mtx);
337 return USB_UNSUPPORT;
341 usb_cb_setup (uint8_t req, uint8_t req_no,
342 uint16_t value, uint16_t index, uint16_t len)
344 uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
346 if (type_rcp == (VENDOR_REQUEST | DEVICE_RECIPIENT))
348 if (USB_SETUP_GET (req))
350 if (req_no == USB_FSIJ_MEMINFO)
352 usb_lld_set_data_to_send (mem_info, sizeof (mem_info));
355 else if (req_no == USB_NEUG_GET_INFO)
358 usb_lld_set_data_to_send (&neug_mode, sizeof (uint8_t));
360 usb_lld_set_data_to_send (&neug_err_cnt, sizeof (uint16_t));
362 usb_lld_set_data_to_send (&neug_err_cnt_rc, sizeof (uint16_t));
364 usb_lld_set_data_to_send (&neug_err_cnt_p64, sizeof (uint16_t));
366 usb_lld_set_data_to_send (&neug_err_cnt_p4k, sizeof (uint16_t));
368 usb_lld_set_data_to_send (&neug_rc_max, sizeof (uint16_t));
370 usb_lld_set_data_to_send (&neug_p64_max, sizeof (uint16_t));
372 usb_lld_set_data_to_send (&neug_p4k_max, sizeof (uint16_t));
374 return USB_UNSUPPORT;
381 uint8_t *addr = (uint8_t *)(0x20000000 + value * 0x100 + index);
383 if (req_no == USB_FSIJ_DOWNLOAD)
385 if (fsij_device_state != FSIJ_DEVICE_EXITED)
386 return USB_UNSUPPORT;
388 if (addr < &_regnual_start || addr + len > &__heap_end__)
389 return USB_UNSUPPORT;
391 if (index + len < 256)
392 memset (addr + index + len, 0, 256 - (index + len));
394 usb_lld_set_data_to_recv (addr, len);
397 else if (req_no == USB_FSIJ_EXEC && len == 0)
399 if (fsij_device_state != FSIJ_DEVICE_EXITED)
400 return USB_UNSUPPORT;
402 if (((uint32_t)addr & 0x03))
403 return USB_UNSUPPORT;
405 return download_check_crc32 ((uint32_t *)addr);
407 else if (req_no == USB_NEUG_EXIT && len == 0)
409 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
410 return USB_UNSUPPORT;
412 fsij_device_state = FSIJ_DEVICE_NEUG_EXIT_REQUESTED;
413 chopstx_wakeup_usec_wait (main_thd);
419 else if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
421 return vcom_port_data_setup (req, req_no, value);
423 return USB_UNSUPPORT;
427 usb_cb_get_descriptor (uint8_t desc_type, uint16_t index, uint16_t value)
430 if (desc_type == DEVICE_DESCRIPTOR)
432 usb_lld_set_data_to_send (vcom_device_desc, sizeof (vcom_device_desc));
435 else if (desc_type == CONFIG_DESCRIPTOR)
437 usb_lld_set_data_to_send (vcom_configuration_desc,
438 sizeof (vcom_configuration_desc));
441 else if (desc_type == STRING_DESCRIPTOR)
443 uint8_t desc_index = value & 0xff;
451 size = sizeof (vcom_string0);
454 str = neug_string_vendor;
455 size = sizeof (neug_string_vendor);
458 str = neug_string_product;
459 size = sizeof (neug_string_product);
463 size = sizeof (vcom_string3);
466 str = neug_revision_detail;
467 size = sizeof (neug_revision_detail);
470 str = neug_config_options;
471 size = sizeof (neug_config_options);
475 size = sizeof (sys_version);
478 return USB_UNSUPPORT;
481 usb_lld_set_data_to_send (str, size);
485 return USB_UNSUPPORT;
489 neug_setup_endpoints_for_interface (uint16_t interface, int stop)
494 usb_lld_setup_endpoint (ENDP2, EP_INTERRUPT, 0, 0, ENDP2_TXADDR, 0);
496 usb_lld_stall_tx (ENDP2);
498 else if (interface == 1)
502 usb_lld_setup_endpoint (ENDP1, EP_BULK, 0, 0, ENDP1_TXADDR, 0);
503 usb_lld_setup_endpoint (ENDP3, EP_BULK, 0, ENDP3_RXADDR, 0, 64);
507 usb_lld_stall_tx (ENDP1);
508 usb_lld_stall_rx (ENDP3);
513 int usb_cb_handle_event (uint8_t event_type, uint16_t value)
516 uint8_t current_conf;
520 case USB_EVENT_ADDRESS:
521 bDeviceState = ADDRESSED;
523 case USB_EVENT_CONFIG:
524 current_conf = usb_lld_current_configuration ();
525 if (current_conf == 0)
528 return USB_UNSUPPORT;
530 usb_lld_set_configuration (1);
531 for (i = 0; i < NUM_INTERFACES; i++)
532 neug_setup_endpoints_for_interface (i, 0);
533 bDeviceState = CONFIGURED;
535 else if (current_conf != value)
538 return USB_UNSUPPORT;
540 usb_lld_set_configuration (0);
541 for (i = 0; i < NUM_INTERFACES; i++)
542 neug_setup_endpoints_for_interface (i, 1);
543 bDeviceState = ADDRESSED;
545 /* Do nothing when current_conf == value */
553 return USB_UNSUPPORT;
557 int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
559 static uint8_t zero = 0;
561 if (interface >= NUM_INTERFACES)
562 return USB_UNSUPPORT;
566 case USB_SET_INTERFACE:
568 return USB_UNSUPPORT;
571 neug_setup_endpoints_for_interface (interface, 0);
575 case USB_GET_INTERFACE:
576 usb_lld_set_data_to_send (&zero, 1);
580 case USB_QUERY_INTERFACE:
585 #define INTR_REQ_USB 20
591 chopstx_intr_t interrupt;
594 asm volatile ("cpsid i" : : : "memory");
595 /* Disable because usb_lld_init assumes interrupt handler. */
596 usb_lld_init (vcom_configuration_desc[7]);
597 chopstx_claim_irq (&interrupt, INTR_REQ_USB);
599 asm volatile ("cpsie i" : : : "memory");
603 chopstx_intr_wait (&interrupt);
605 /* Process interrupt. */
606 usb_interrupt_handler ();
613 static void fill_serial_no_by_unique_id (void)
615 extern const uint8_t * unique_device_id (void);
616 uint8_t *p = &vcom_string3[12];
617 const uint8_t *u = unique_device_id ();
620 for (i = 0; i < 4; i++)
626 nibble += (nibble >= 10 ? ('A' - 10) : '0');
629 nibble += (nibble >= 10 ? ('A' - 10) : '0');
635 EP1_IN_Callback (void)
637 chopstx_mutex_lock (&usb_mtx);
638 chopstx_cond_signal (&cnd_usb);
639 chopstx_mutex_unlock (&usb_mtx);
643 EP2_IN_Callback (void)
648 EP3_OUT_Callback (void)
650 usb_lld_rx_enable (ENDP3);
653 typedef uint32_t eventmask_t;
654 #define ALL_EVENTS (~0)
657 chopstx_mutex_t mutex;
662 static void event_flag_init (struct event_flag *ev)
665 chopstx_mutex_init (&ev->mutex);
666 chopstx_cond_init (&ev->cond);
670 static eventmask_t event_flag_waitone (struct event_flag *ev, eventmask_t m)
674 chopstx_mutex_lock (&ev->mutex);
675 while (!(ev->flag & m))
676 chopstx_cond_wait (&ev->cond, &ev->mutex);
678 n = __builtin_ffs ((ev->flag & m));
679 ev->flag &= ~(1 << (n - 1));
680 chopstx_mutex_unlock (&ev->mutex);
682 return (1 << (n - 1));
685 static void event_flag_signal (struct event_flag *ev, eventmask_t m)
687 chopstx_mutex_lock (&ev->mutex);
689 chopstx_cond_signal (&ev->cond);
690 chopstx_mutex_unlock (&ev->mutex);
693 extern uint8_t __process1_stack_base__, __process1_stack_size__;
694 extern uint8_t __process3_stack_base__, __process3_stack_size__;
696 const uint32_t __stackaddr_led = (uint32_t)&__process1_stack_base__;
697 const size_t __stacksize_led = (size_t)&__process1_stack_size__;
698 const uint32_t __stackaddr_usb = (uint32_t)&__process3_stack_base__;
699 const size_t __stacksize_usb = (size_t)&__process3_stack_size__;
703 struct event_flag led_event;
705 #define LED_ONESHOT_SHORT ((eventmask_t)1)
706 #define LED_TWOSHOTS ((eventmask_t)2)
707 #define LED_ONESHOT_LONG ((eventmask_t)4)
710 * LED blinker: When notified, let LED emit for 100ms.
712 static void *led_blinker (void *arg)
722 m = event_flag_waitone (&led_event, ALL_EVENTS);
723 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
727 if (m == LED_ONESHOT_SHORT)
728 chopstx_usec_wait (100*1000);
729 else if (m == LED_TWOSHOTS)
731 chopstx_usec_wait (50*1000);
733 chopstx_usec_wait (50*1000);
735 chopstx_usec_wait (50*1000);
738 chopstx_usec_wait (250*1000);
745 #define RANDOM_BYTES_LENGTH 64
746 static uint32_t random_word[RANDOM_BYTES_LENGTH/sizeof (uint32_t)];
748 static void copy_to_tx (uint32_t v, int i)
750 usb_lld_txcpy (&v, ENDP1, i * 4, 4);
754 * In Gnuk 1.0.[12], reGNUal was not relocatable.
755 * Now, it's relocatable, but we need to calculate its entry address
756 * based on it's pre-defined address.
758 #define REGNUAL_START_ADDRESS_COMPATIBLE 0x20001400
760 calculate_regnual_entry_address (const uint8_t *addr)
762 const uint8_t *p = addr + 4;
763 uint32_t v = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
765 v -= REGNUAL_START_ADDRESS_COMPATIBLE;
774 * NOTE: the main function is already a thread in the system on entry.
777 main (int argc, char **argv)
780 chopstx_t led_thread, usb_thd;
785 fill_serial_no_by_unique_id ();
789 event_flag_init (&led_event);
792 led_thread = chopstx_create (PRIO_LED, __stackaddr_led, __stacksize_led,
795 chopstx_mutex_init (&usb_mtx);
796 chopstx_cond_init (&cnd_usb);
798 usb_thd = chopstx_create (PRIO_USB, __stackaddr_usb, __stacksize_usb,
801 neug_init (random_word, RANDOM_BYTES_LENGTH/sizeof (uint32_t));
805 unsigned int count = 0;
806 int last_was_fullsizepacket = 0;
808 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
811 while (count < NEUG_PRE_LOOP || bDeviceState != CONFIGURED)
813 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
819 if ((count & 0x0007) == 0)
820 event_flag_signal (&led_event, LED_ONESHOT_SHORT);
821 chopstx_usec_wait (25*1000);
826 while (connected == 0)
828 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
832 event_flag_signal (&led_event, LED_TWOSHOTS);
833 chopstx_usec_wait (5000*1000);
836 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
839 /* The connection opened. */
842 * No parity is standard. It means to provide conditioned output.
843 * When parity enabled, it means to provide raw output.
845 neug_mode_select (line_coding.paritytype); /* 0: None, 1: Odd, 2: Even */
851 if (fsij_device_state != FSIJ_DEVICE_RUNNING)
854 if (bDeviceState != CONFIGURED)
857 if ((count & 0x03ff) == 0)
858 event_flag_signal (&led_event, LED_ONESHOT_SHORT);
860 i = neug_consume_random (copy_to_tx);
862 if (i == 0 && !last_was_fullsizepacket)
863 { /* Only send ZLP when the last packet was fullsize. */
869 last_was_fullsizepacket = 1;
871 last_was_fullsizepacket = 0;
873 chopstx_mutex_lock (&usb_mtx);
876 chopstx_mutex_unlock (&usb_mtx);
877 goto waiting_connection;
881 usb_lld_tx_enable (ENDP1, i * 4);
882 chopstx_cond_wait (&cnd_usb, &usb_mtx);
884 chopstx_mutex_unlock (&usb_mtx);
890 chopstx_cancel (led_thread);
891 chopstx_join (led_thread, NULL);
894 * We come here, because of FSIJ_DEVICE_NEUG_EXIT_REQUESTED.
898 fsij_device_state = FSIJ_DEVICE_EXITED;
900 while (fsij_device_state == FSIJ_DEVICE_EXITED)
901 chopstx_usec_wait (500*1000);
903 flash_unlock (); /* Flash unlock should be done here */
907 /* Finish application. */
908 chopstx_cancel (usb_thd);
909 chopstx_join (usb_thd, NULL);
912 SCB->VTOR = (uint32_t)&_regnual_start;
913 entry = calculate_regnual_entry_address (&_regnual_start);
915 #define FLASH_SYS_START_ADDR 0x08000000
916 #define FLASH_SYS_END_ADDR (0x08000000+0x1000)
920 handler *new_vector = (handler *)FLASH_SYS_START_ADDR;
921 void (*func) (void (*)(void)) = (void (*)(void (*)(void)))new_vector[10];
924 for (addr = FLASH_SYS_START_ADDR; addr < FLASH_SYS_END_ADDR;
925 addr += FLASH_PAGE_SIZE)
926 flash_erase_page (addr);
928 /* copy system service routines */
929 flash_write (FLASH_SYS_START_ADDR, &_sys, 0x1000);
931 /* Leave NeuG to exec reGNUal */
932 (*func) ((void (*)(void))entry);
936 /* Leave NeuG to exec reGNUal */
937 flash_erase_all_and_exec ((void (*)(void))entry);