Changeset 8ff0bd2 in mainline for boot


Ignore:
Timestamp:
2011-09-04T11:30:58Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03bc76a
Parents:
d2c67e7 (diff), deac215e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
boot
Files:
16 added
2 deleted
15 edited
2 moved

Legend:

Unmodified
Added
Removed
  • boot/Makefile

    rd2c67e7 r8ff0bd2  
    5050        $(MKFAT) 1048576 $(DIST_PATH) $@
    5151endif
     52ifeq ($(RDFMT),ext2fs)
     53        $(MKEXT2) 1048576 $(DIST_PATH) $@
     54endif
    5255
    5356build_dist: clean_dist
     
    6568        done
    6669        for drv in $(RD_DRVS) ; do \
    67                 mkdir -p "$(DIST_PATH)/$(DRVS_PATH)/$$drv" ; \
    68                 cp "$(USPACE_PATH)/$(DRVS_PATH)/$$drv/$$drv" "$(DIST_PATH)/$(DRVS_PATH)/$$drv/$$drv" ; \
    69                 cp "$(USPACE_PATH)/$(DRVS_PATH)/$$drv/$$drv.ma" "$(DIST_PATH)/$(DRVS_PATH)/$$drv/$$drv.ma" ; \
     70                drv_dir="`dirname "$$drv"`" ; \
     71                drv_name="`basename "$$drv"`" ; \
     72                mkdir -p "$(DIST_PATH)/$(DRVS_PATH)/$$drv_name" ; \
     73                cp "$(USPACE_PATH)/$(DRVS_PATH)/$$drv_dir/$$drv_name/$$drv_name" "$(DIST_PATH)/$(DRVS_PATH)/$$drv_name/" ; \
     74                cp "$(USPACE_PATH)/$(DRVS_PATH)/$$drv_dir/$$drv_name/$$drv_name.ma" "$(DIST_PATH)/$(DRVS_PATH)/$$drv_name/" ; \
    7075        done
    7176        for file in $(RD_DRV_CFG) ; do \
    72                 cp "$(USPACE_PATH)/$(DRVS_PATH)/$$file" "$(DIST_PATH)/$(DRVS_PATH)/$$file" ; \
     77                file_dir="`dirname "$$file"`" ; \
     78                file_name="`basename "$$file"`" ; \
     79                cp "$(USPACE_PATH)/$(DRVS_PATH)/$$file_dir/$$file_name/$$file_name.dev" "$(DIST_PATH)/$(DRVS_PATH)/$$file_name/" ; \
    7380        done
    74        
     81
    7582clean: clean_dist
    7683        $(MAKE) -f $(BUILD) clean PRECHECK=$(PRECHECK)
  • boot/Makefile.common

    rd2c67e7 r8ff0bd2  
    5656MKTMPFS = $(TOOLS_PATH)/mktmpfs.py
    5757MKFAT = $(TOOLS_PATH)/mkfat.py
     58MKEXT2 = $(TOOLS_PATH)/mkext2.py
    5859MKUIMAGE = $(TOOLS_PATH)/mkuimage.py
    5960
     
    7273        $(USPACE_PATH)/srv/loader/loader \
    7374        $(USPACE_PATH)/app/init/init \
    74         $(USPACE_PATH)/srv/devmap/devmap \
     75        $(USPACE_PATH)/srv/loc/loc \
    7576        $(USPACE_PATH)/srv/bd/rd/rd \
    7677        $(USPACE_PATH)/srv/vfs/vfs
     
    8485endif
    8586
     87ifeq ($(RDFMT),ext2fs)
     88        INIT_TASKS += $(USPACE_PATH)/srv/fs/ext2fs/ext2fs
     89endif
     90
    8691RD_SRVS_ESSENTIAL = \
    8792        $(USPACE_PATH)/srv/hid/fb/fb \
    88         $(USPACE_PATH)/srv/hid/kbd/kbd \
     93        $(USPACE_PATH)/srv/hid/input/input \
    8994        $(USPACE_PATH)/srv/hid/console/console \
    90         $(USPACE_PATH)/srv/fs/devfs/devfs
     95        $(USPACE_PATH)/srv/fs/locfs/locfs
    9196
    9297RD_SRVS_NON_ESSENTIAL = \
     
    98103        $(USPACE_PATH)/srv/fs/fat/fat \
    99104        $(USPACE_PATH)/srv/fs/minixfs/mfs \
     105        $(USPACE_PATH)/srv/fs/exfat/exfat \
    100106        $(USPACE_PATH)/srv/fs/ext2fs/ext2fs \
    101107        $(USPACE_PATH)/srv/taskmon/taskmon \
     
    111117        $(USPACE_PATH)/srv/net/net/net \
    112118        $(USPACE_PATH)/srv/devman/devman
    113        
     119
    114120RD_DRVS = \
    115         root \
    116         rootvirt \
    117         test1 \
    118         test2 \
    119         test3
    120 
    121 RD_DRV_CFG = 
     121        infrastructure/root \
     122        infrastructure/rootvirt \
     123        test/test1 \
     124        test/test2 \
     125        test/test3
     126
     127RD_DRV_CFG =
    122128
    123129RD_LIBS =
     
    139145        $(USPACE_PATH)/app/blkdump/blkdump \
    140146        $(USPACE_PATH)/app/bnchmark/bnchmark \
     147        $(USPACE_PATH)/app/devctl/devctl \
    141148        $(USPACE_PATH)/app/dltest/dltest \
    142149        $(USPACE_PATH)/app/dltest2/dltest2 \
     
    146153        $(USPACE_PATH)/app/kill/kill \
    147154        $(USPACE_PATH)/app/killall/killall \
     155        $(USPACE_PATH)/app/locinfo/locinfo \
    148156        $(USPACE_PATH)/app/mkfat/mkfat \
    149157        $(USPACE_PATH)/app/mkminix/mkminix \
  • boot/Makefile.silo

    rd2c67e7 r8ff0bd2  
    3131include Makefile.common
    3232
    33 ifeq ($(CONFIG_AOUT_ISOFS_B),y)
    34         SILO_PACKAGE = a.out
    35 else
    36         SILO_PACKAGE = raw
    37 endif
     33SILO_PACKAGE = a.out
    3834
    3935ISOFS_B = silo/$(SILO_PACKAGE)/isofs.b
  • boot/Makefile.uboot

    rd2c67e7 r8ff0bd2  
    3131include Makefile.common
    3232
    33 IMAGE_NAME=HelenOS-$(RELEASE)
    34 BIN_OUTPUT=image.bin
     33IMAGE_NAME = HelenOS-$(RELEASE)
     34BIN_OUTPUT = image.bin
    3535
    3636all: $(POST_OUTPUT)
     
    4040
    4141$(POST_OUTPUT): $(BIN_OUTPUT)
    42         $(MKUIMAGE) -name "$(IMAGE_NAME)" -laddr 0x30008000 -saddr 0x30008000 \
    43     $< $@
     42        $(MKUIMAGE) -name "$(IMAGE_NAME)" -laddr 0x30008000 -saddr 0x30008000 $< $@
    4443
    4544clean:
  • boot/arch/amd64/Makefile.inc

    rd2c67e7 r8ff0bd2  
    3535
    3636RD_SRVS_NON_ESSENTIAL += \
    37         $(USPACE_PATH)/srv/bd/ata_bd/ata_bd \
    38         $(USPACE_PATH)/srv/hid/char_mouse/char_ms
     37        $(USPACE_PATH)/srv/bd/ata_bd/ata_bd
    3938
    4039RD_DRVS += \
    41         rootpc \
    42         pciintel \
    43         isa \
    44         ns8250 \
    45         ehci_hcd \
    46         ohci \
    47         uhci_hcd \
    48         uhci_rhd \
    49         usbflbk \
    50         usbhub \
    51         usbhid \
    52         usbmast \
    53         usbmid \
    54         usbmouse \
    55         vhc
     40        infrastructure/rootpc \
     41        bus/pci/pciintel \
     42        bus/isa \
     43        char/ns8250 \
     44        bus/usb/ehci\
     45        bus/usb/ohci \
     46        bus/usb/uhci \
     47        bus/usb/uhcirh \
     48        bus/usb/usbflbk \
     49        bus/usb/usbhub \
     50        bus/usb/usbhid \
     51        bus/usb/usbmast \
     52        bus/usb/usbmid \
     53        bus/usb/usbmouse \
     54        bus/usb/vhc
    5655
    5756RD_DRV_CFG += \
    58         isa/isa.dev
     57        bus/isa
    5958
    6059BOOT_OUTPUT = $(ROOT_PATH)/image.iso
  • boot/arch/ia64/Makefile.inc

    rd2c67e7 r8ff0bd2  
    4545        arch/$(BARCH)/src/asm.S \
    4646        arch/$(BARCH)/src/main.c \
     47        arch/$(BARCH)/src/sal.c \
     48        arch/$(BARCH)/src/sal_asm.S \
     49        arch/$(BARCH)/src/pal.c \
     50        arch/$(BARCH)/src/pal_asm.S \
    4751        arch/$(BARCH)/src/putchar.c \
    4852        $(COMPS_C) \
     53        genarch/src/efi.c \
    4954        genarch/src/division.c \
    5055        generic/src/balloc.c \
  • boot/arch/ia64/include/pal.h

    rd2c67e7 r8ff0bd2  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2011 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
    30  * @{
     29#ifndef BOOT_ia64_PAL_H_
     30#define BOOT_ia64_PAL_H_
     31
     32#include <arch/types.h>
     33#include <typedefs.h>
     34
     35/*
     36 * Essential PAL procedures' IDs
    3137 */
    32 /** @file
    33  */
     38#define PAL_FREQ_RATIOS         14     
    3439
    35 #ifndef LIBC_DEVMAP_OBSOLETE_H_
    36 #define LIBC_DEVMAP_OBSOLETE_H_
     40extern uint64_t pal_proc_freq_ratio(void);
    3741
    38 #include <ipc/devmap.h>
    39 #include <async.h>
    40 #include <bool.h>
     42#define pal_static_call_0_1(id, ret1) \
     43        pal_static_call((id), 0, 0, 0, (ret1), NULL, NULL)
    4144
    42 extern int devmap_obsolete_get_phone(devmap_interface_t, unsigned int);
    43 extern void devmap_obsolete_hangup_phone(devmap_interface_t iface);
    44 
    45 extern int devmap_obsolete_device_connect(devmap_handle_t, unsigned int);
     45extern uint64_t pal_static_call(uint64_t, uint64_t, uint64_t, uint64_t,
     46    uint64_t *, uint64_t *, uint64_t *);
    4647
    4748#endif
    48 
    49 /** @}
    50  */
  • boot/arch/ia64/include/types.h

    rd2c67e7 r8ff0bd2  
    3030#define BOOT_ia64_TYPES_H_
    3131
     32#include <arch/common.h>
     33
    3234#define TASKMAP_MAX_RECORDS             32
    3335#define BOOTINFO_TASK_NAME_BUFLEN       32
    34 #define MEMMAP_ITEMS                    128     
     36#define MEMMAP_ITEMS                    128
    3537
    3638typedef uint64_t size_t;
     
    5355        unsigned long base;
    5456        unsigned long size;
    55 } efi_memmap_item_t;
     57} memmap_item_t;
    5658
    5759typedef struct {
    5860        binit_t taskmap;
    5961
    60         efi_memmap_item_t memmap[MEMMAP_ITEMS];
     62        memmap_item_t memmap[MEMMAP_ITEMS];
    6163        unsigned int memmap_items;
    6264
     
    6567        unsigned long freq_scale;
    6668        unsigned int wakeup_intno;
    67         int hello_configured;
    6869} bootinfo_t;
    6970
     71/** This is a minimal ELILO-compatible boot parameter structure. */
     72typedef struct {
     73        uint64_t cmd_line;
     74        uint64_t efi_system_table;
     75        uint64_t efi_memmap;
     76        uint64_t efi_memmap_sz;
     77        uint64_t efi_memdesc_sz;
     78} boot_param_t;
     79
    7080#endif
  • boot/arch/ia64/src/boot.S

    rd2c67e7 r8ff0bd2  
    3737
    3838        #
     39        # Save the boot parameter structure address passed from the
     40        # ELILO-compatible EFI loader.
     41        #
     42        movl r8 = bootpar ;;
     43        st8 [r8] = r28
     44
     45        #
    3946        # Initialize the register stack to some sane value.
    4047        #
     
    6269.bss
    6370
     71.global bootpar
     72bootpar:
     73        .quad 0
     74
    6475.align STACK_SIZE
    6576initial_stack:
  • boot/arch/ia64/src/main.c

    rd2c67e7 r8ff0bd2  
    3030
    3131#include <arch/main.h>
     32#include <arch/types.h>
    3233#include <arch/arch.h>
    3334#include <arch/asm.h>
    3435#include <arch/_components.h>
     36#include <genarch/efi.h>
     37#include <arch/sal.h>
     38#include <arch/pal.h>
    3539#include <halt.h>
    3640#include <printf.h>
     
    5155#define DEFAULT_SYS_FREQ                100000000ULL            /* 100MHz */
    5256
    53 #define EFI_MEMMAP_FREE_MEM             0
    54 #define EFI_MEMMAP_IO                   1
    55 #define EFI_MEMMAP_IO_PORTS             2
     57#define MEMMAP_FREE_MEM         0
     58#define MEMMAP_IO               1
     59#define MEMMAP_IO_PORTS         2
     60
     61extern boot_param_t *bootpar;
    5662
    5763static bootinfo_t bootinfo;
     64
     65static void read_efi_memmap(void)
     66{
     67        memmap_item_t *memmap = bootinfo.memmap;
     68        size_t items = 0;
     69       
     70        if (!bootpar) {
     71                /* Fake-up a memory map for simulators. */
     72                memmap[items].base = DEFAULT_MEMORY_BASE;
     73                memmap[items].size = DEFAULT_MEMORY_SIZE;
     74                memmap[items].type = MEMMAP_FREE_MEM;
     75                items++;
     76
     77                memmap[items].base = DEFAULT_LEGACY_IO_BASE;
     78                memmap[items].size = DEFAULT_LEGACY_IO_SIZE;
     79                memmap[items].type = MEMMAP_IO_PORTS;
     80                items++;                 
     81        } else {
     82                char *cur, *mm_base = (char *) bootpar->efi_memmap;
     83                size_t mm_size = bootpar->efi_memmap_sz;
     84                size_t md_size = bootpar->efi_memdesc_sz;
     85               
     86                /*
     87                 * Walk the EFI memory map using the V1 memory descriptor
     88                 * format. The actual memory descriptor can use newer format,
     89                 * but it must always be backwards compatible with the V1
     90                 * format.
     91                 */
     92                for (cur = mm_base;
     93                    (cur < mm_base + (mm_size - md_size)) &&
     94                    (items < MEMMAP_ITEMS);
     95                    cur += md_size) {
     96                        efi_v1_memdesc_t *md = (efi_v1_memdesc_t *) cur;
     97
     98                        switch ((efi_memory_type_t) md->type) {
     99                        case EFI_CONVENTIONAL_MEMORY:
     100                                memmap[items].type = MEMMAP_FREE_MEM;
     101                                break;
     102                        case EFI_MEMORY_MAPPED_IO:
     103                                memmap[items].type = MEMMAP_IO;
     104                                break;
     105                        case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
     106                                memmap[items].type = MEMMAP_IO_PORTS;
     107                                break;
     108                        default:
     109                                continue;
     110                        }
     111                       
     112                        memmap[items].base = md->phys_start;
     113                        memmap[items].size = md->pages * EFI_PAGE_SIZE;
     114                        items++;
     115                }
     116        }
     117       
     118        bootinfo.memmap_items = items;
     119}
     120
     121static void read_pal_configuration(void)
     122{
     123        if (bootpar) {
     124                bootinfo.freq_scale = pal_proc_freq_ratio();
     125        } else {
     126                /* Configure default values for simulators. */
     127                bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
     128        }
     129}
     130
     131static void read_sal_configuration(void)
     132{
     133        if (bootpar && bootpar->efi_system_table) {
     134                efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID;
     135                sal_system_table_header_t *sal_st;
     136               
     137                sal_st = efi_vendor_table_find(
     138                    (efi_system_table_t *) bootpar->efi_system_table, sal_guid);
     139
     140                sal_system_table_parse(sal_st);
     141               
     142                bootinfo.sys_freq = sal_base_clock_frequency();
     143        } else {
     144                /* Configure default values for simulators. */
     145                bootinfo.sys_freq = DEFAULT_SYS_FREQ;
     146        }
     147}
    58148
    59149void bootstrap(void)
     
    113203       
    114204        printf(".\n");
    115        
    116         if (!bootinfo.hello_configured) {       /* XXX */
    117                 /*
    118                  * Load configuration defaults for simulators.
    119                  */
    120                  bootinfo.memmap_items = 0;
    121                  
    122                  bootinfo.memmap[bootinfo.memmap_items].base =
    123                      DEFAULT_MEMORY_BASE;
    124                  bootinfo.memmap[bootinfo.memmap_items].size =
    125                      DEFAULT_MEMORY_SIZE;
    126                  bootinfo.memmap[bootinfo.memmap_items].type =
    127                      EFI_MEMMAP_FREE_MEM;
    128                  bootinfo.memmap_items++;
    129 
    130                  bootinfo.memmap[bootinfo.memmap_items].base =
    131                      DEFAULT_LEGACY_IO_BASE;
    132                  bootinfo.memmap[bootinfo.memmap_items].size =
    133                      DEFAULT_LEGACY_IO_SIZE;
    134                  bootinfo.memmap[bootinfo.memmap_items].type =
    135                      EFI_MEMMAP_IO_PORTS;
    136                  bootinfo.memmap_items++;
    137                  
    138                  bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
    139                  bootinfo.sys_freq = DEFAULT_SYS_FREQ;
    140         }
    141        
     205
     206        read_efi_memmap();
     207        read_sal_configuration();
     208        read_pal_configuration();
    142209       
    143210        printf("Booting the kernel ...\n");
  • boot/arch/ia64/src/sal.c

    rd2c67e7 r8ff0bd2  
    11/*
    2  * Copyright (c) 2006 Jakub Jermar
     2 * Copyright (c) 2011 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef KERN_FHC_H_
    30 #define KERN_FHC_H_
     29#include <arch/sal.h>
     30#include <arch/types.h>
    3131
    32 #include <genarch/ofw/ofw_tree.h>
    33 #include <typedefs.h>
    34 #include <ddi/irq.h>
    35 #include <typedefs.h>
     32static sal_ap_wakeup_desc_t *sal_ap_wakeup;
    3633
    37 typedef struct {
    38         uint64_t addr;
    39         uint32_t size;
    40 } __attribute__ ((packed)) ofw_fhc_reg_t;
     34extern uint64_t pal_proc;
    4135
    42 typedef struct {
    43         uint64_t child_base;
    44         uint64_t parent_base;
    45         uint32_t size;
    46 } __attribute__ ((packed)) ofw_fhc_range_t;
     36uint64_t sal_proc = 0;
     37uint64_t sal_proc_gp = 0;
    4738
    48 typedef struct {
    49         uint64_t addr;
    50         uint32_t size;
    51 } __attribute__ ((packed)) ofw_central_reg_t;
     39void sal_system_table_parse(sal_system_table_header_t *sst)
     40{
     41        uint8_t *cur = (uint8_t *) &sst[1];
     42        uint16_t entry;
    5243
    53 typedef struct {
    54         uint64_t child_base;
    55         uint64_t parent_base;
    56         uint32_t size;
    57 } __attribute__ ((packed)) ofw_central_range_t;
     44        for (entry = 0; entry < sst->entry_count; entry++) {
     45                switch ((sal_sst_type_t) *cur) {
     46                case SSTT_ENTRYPOINT_DESC:
     47                        pal_proc = ((sal_entrypoint_desc_t *) cur)->pal_proc;
     48                        sal_proc = ((sal_entrypoint_desc_t *) cur)->sal_proc;
     49                        sal_proc_gp = ((sal_entrypoint_desc_t *) cur)->sal_proc_gp;
     50                        cur += sizeof(sal_entrypoint_desc_t);
     51                        break;
     52                case SSTT_MEMORY_DESC:
     53                        cur += sizeof(sal_memory_desc_t);
     54                        break;
     55                case SSTT_PLATFORM_FEATURES_DESC:
     56                        cur += sizeof(sal_platform_features_desc_t);
     57                        break;
     58                case SSTT_TR_DESC:
     59                        cur += sizeof(sal_tr_desc_t);
     60                        break;
     61                case SSTT_PTC_COHERENCE_DOMAIN_DESC:
     62                        cur += sizeof(sal_ptc_coherence_domain_desc_t);
     63                        break;
     64                case SSTT_AP_WAKEUP_DESC:
     65                        sal_ap_wakeup = (sal_ap_wakeup_desc_t *) cur;
     66                        cur += sizeof(sal_ap_wakeup_desc_t);
     67                        break;
     68                default:
     69                        return;
     70                }
     71        }
     72}
    5873
    59 extern bool ofw_fhc_apply_ranges(ofw_tree_node_t *, ofw_fhc_reg_t *,
    60     uintptr_t *);
    61 extern bool ofw_central_apply_ranges(ofw_tree_node_t *, ofw_central_reg_t *,
    62     uintptr_t *);
    63 
    64 extern bool ofw_fhc_map_interrupt(ofw_tree_node_t *, ofw_fhc_reg_t *,
    65     uint32_t, int *, cir_t *, void **);
    66 
    67 #endif
     74uint64_t sal_base_clock_frequency(void)
     75{
     76        uint64_t freq;
     77       
     78        sal_call_1_1(SAL_FREQ_BASE, 0, &freq);
     79       
     80        return freq;
     81}
  • boot/arch/mips32/Makefile.inc

    rd2c67e7 r8ff0bd2  
    3030BITS = 32
    3131PAGE_SIZE = 16384
    32 EXTRA_CFLAGS = -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mips3
    33 
    34 RD_SRVS_ESSENTIAL +=
     32EXTRA_CFLAGS = -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mips3 -mabi=32
    3533
    3634RD_SRVS_NON_ESSENTIAL += \
  • boot/arch/mips32/src/asm.S

    rd2c67e7 r8ff0bd2  
    4444         * Setup the CP0 configuration
    4545         *  - Disable 64-bit kernel addressing mode
    46          *  - DIsable 64-bit supervisor adressing mode
     46         *  - Disable 64-bit supervisor adressing mode
    4747         *  - Disable 64-bit user addressing mode
    4848         */
  • boot/arch/ppc32/Makefile.inc

    rd2c67e7 r8ff0bd2  
    4343        $(USPACE_PATH)/srv/hw/bus/cuda_adb/cuda_adb
    4444
    45 RD_SRVS_NON_ESSENTIAL += \
    46         $(USPACE_PATH)/srv/hid/adb_mouse/adb_ms
     45RD_DRVS += \
     46        infrastructure/rootmac
    4747
    4848SOURCES = \
  • boot/arch/sparc64/Makefile.inc

    rd2c67e7 r8ff0bd2  
    4343
    4444RD_SRVS_ESSENTIAL += \
    45         $(USPACE_PATH)/srv/hw/irc/fhc/fhc \
    4645        $(USPACE_PATH)/srv/hw/irc/obio/obio
    4746
  • boot/arch/sparc64/src/main.c

    rd2c67e7 r8ff0bd2  
    182182         * of the "/memory" node to find out which parts of memory
    183183         * are used by OBP and redesign the algorithm of copying
    184          * kernel/init tasks/ramdisk from the bootable image to memory
    185          * (which we must do anyway because of issues with claiming the memory
    186          * on Serengeti).
    187          *
     184         * kernel/init tasks/ramdisk from the bootable image to memory.
    188185         */
    189186        bootinfo.physmem_start += OBP_BIAS;
  • boot/generic/src/printf_core.c

    rd2c67e7 r8ff0bd2  
    7070 */
    7171#define PRINT_NUMBER_BUFFER_SIZE  (64 + 5)
     72
     73/** Get signed or unsigned integer argument */
     74#define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \
     75        ({ \
     76                unsigned type res; \
     77                \
     78                if ((flags) & __PRINTF_FLAG_SIGNED) { \
     79                        signed type arg = va_arg((ap), signed type); \
     80                        \
     81                        if (arg < 0) { \
     82                                res = -arg; \
     83                                (flags) |= __PRINTF_FLAG_NEGATIVE; \
     84                        } else \
     85                                res = arg; \
     86                } else \
     87                        res = va_arg((ap), unsigned type); \
     88                \
     89                res; \
     90        })
    7291
    7392/** Enumeration of possible arguments types.
     
    171190        }
    172191       
    173         return (int) (counter + 1);
     192        return (int) (counter);
    174193}
    175194
     
    698717                        size_t size;
    699718                        uint64_t number;
     719                       
    700720                        switch (qualifier) {
    701721                        case PrintfQualifierByte:
    702722                                size = sizeof(unsigned char);
    703                                 number = (uint64_t) va_arg(ap, unsigned int);
     723                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    704724                                break;
    705725                        case PrintfQualifierShort:
    706726                                size = sizeof(unsigned short);
    707                                 number = (uint64_t) va_arg(ap, unsigned int);
     727                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    708728                                break;
    709729                        case PrintfQualifierInt:
    710730                                size = sizeof(unsigned int);
    711                                 number = (uint64_t) va_arg(ap, unsigned int);
     731                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    712732                                break;
    713733                        case PrintfQualifierLong:
    714734                                size = sizeof(unsigned long);
    715                                 number = (uint64_t) va_arg(ap, unsigned long);
     735                                number = PRINTF_GET_INT_ARGUMENT(long, ap, flags);
    716736                                break;
    717737                        case PrintfQualifierLongLong:
    718738                                size = sizeof(unsigned long long);
    719                                 number = (uint64_t) va_arg(ap, unsigned long long);
     739                                number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags);
    720740                                break;
    721741                        case PrintfQualifierPointer:
     
    732752                                counter = -counter;
    733753                                goto out;
    734                         }
    735                        
    736                         if (flags & __PRINTF_FLAG_SIGNED) {
    737                                 if (number & (0x1 << (size * 8 - 1))) {
    738                                         flags |= __PRINTF_FLAG_NEGATIVE;
    739                                        
    740                                         if (size == sizeof(uint64_t)) {
    741                                                 number = -((int64_t) number);
    742                                         } else {
    743                                                 number = ~number;
    744                                                 number &=
    745                                                     ~(0xFFFFFFFFFFFFFFFFll <<
    746                                                     (size * 8));
    747                                                 number++;
    748                                         }
    749                                 }
    750754                        }
    751755                       
Note: See TracChangeset for help on using the changeset viewer.