Nov, 2004 Amit Bhor Codito Technologies www'codito'com - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Nov, 2004 Amit Bhor Codito Technologies www'codito'com

Description:

The sources to the linux kernel. Architecture caveats. Memory ... asm-alpha asm-generic asm-mips asm-ppc64 asm-sparc. asm-i386 asm-mips64 asm-s390 asm-sparc64 ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 20
Provided by: foss
Category:
Tags: amit | bhor | codito | com | nov | technologies | www

less

Transcript and Presenter's Notes

Title: Nov, 2004 Amit Bhor Codito Technologies www'codito'com


1
Nov, 2004Amit Bhor Codito Technologies (
www.codito.com )
Porting Linux to 32 bit RISC processors
2
The Start
  • What do you need to start a Linux port
  • A new 32 bit architecture ( of course ) and a
    development board
  • The GNU tool chain for the new architecture
  • A debugger, preferably over JTAG
  • The sources to the linux kernel
  • Architecture caveats
  • Memory Management Unit ?
  • TRAP or software interrupt mechanism ?
  • Mis-aligned data access ?
  • Defined ABI
  • Similar architectures
  • Cache aliasing

3
Where to add support
  • Architecture specific code
  • TOPDIR/arch
  • alpha arm ia64 mips parisc ppc64 s390x
    sparc x86_64
  • cris i386 m68k mips64 ppc s390 sh
    sparc64
  • TOPDIR/include/asm-
  • asm-alpha asm-generic asm-mips asm-ppc64
    asm-sparc
  • asm-i386 asm-mips64 asm-s390 asm-sparc64
  • asm-arm asm-ia64 asm-parisc asm-s390x
    asm-x86_64
  • asm-cris asm-m68k asm-ppc asm-sh
  • Device drivers serial, ethernet etc.
  • Add new directories for your new processor
  • TOPDIR/arch/arc
  • TOPDIR/arch/asm-arc

4
Code Layout
  • Multiple platforms / boards
  • Multiple processors variants / versions
  • Design the code layout and Architecture HAL
    accordingly
  • Main level layout
  • boot config.in defconfig kernel lib Makefile
    mm proc tools
  • Second level layout
  • Processor specific arc700 arc600 a5 a4
  • Platform specific ( none for ARC )

5
Start Coding
  • Setup Makefiles
  • Kernel linker script linux.lds.in
  • Reuse as much as possible
  • Start with generic implementations
  • TOPDIR/proc/arc700/head.S
  • Read processor identity
  • Initialize BSS
  • Setup frame pointer and stack pointer for the
    kernel
  • mov fp, 0
  • mov sp, _init_task_union 8192
  • Jump to start of the kernel initialization
    start_kernel()
  • sub_s sp, sp, 4
  • jal _start_kernel

6
Important header files
  • TOPDIR/include/asm-arc/system.h
  • __cli() , __sti(), __save_flags_cli(),
    __save_flags(), __restore_flags()
  • define __save_flags_cli(x) \
  • __asm__ __volatile__ ( \
  • "lr r20, status32 \n\t" \
  • "mov 0, r20 \n\t" \
  • "and r20, r20, 1 \n\t" \
  • "flag r20 \n\t" \
  • "r" (x) \
  • "n" ((STATUS_E1_MASK STATUS_E2_MASK)) \
  • "r20", "memory")
  • Memory barrier
  • define mb() __asm__ __volatile__ (""
    "memory")
  • The context switching macro switch_to()

7
Important header files
  • TOPDIR/include/asm-arc/atomic.h
  • Macros on top of the routines in system.h
  • Use generic atomic_ macros
  • TOPDIR/include/asm-arc/entry.h
  • Macros to save and restore context
  • Caller saved and Callee saved registers
  • Interrupt / exception / system call contexts

8
Important header files
  • TOPDIR/include/asm-arc/ptrace.h
  • struct pt_regs
  • / this struct defines the way the registers are
    stored on the
  • stack during a system call. /
  • struct pt_regs
  • long stack_place_holder
  • long bta / bta_l1, bta_l2, erbta /
  • long lp_start
  • long lp_end
  • long lp_count
  • long status32 / status32_l1, status32_l2,
    erstatus /
  • long ret / ilink1, ilink2 or eret /
  • long blink
  • long fp
  • long r26 / gp /
  • long r12

9
Important header files
  • byteorder.h little / big endian
  • checksum.h start with generic C implementations
  • irq.h - irq design , irq register / unregister
    API
  • mmu.h
  • MMU context ( if supported )
  • typedef struct
  • unsigned long asid
  • ifdef CONFIG_ARC_TLB_DBG
  • struct task_struct tsk
  • endif
  • mm_context_t
  • Page Table Entries and associated bit masks
  • Hardware supported
  • Software emulated

10
Important header files
  • unistd.h
  • System call interface, TRAP mechanism
  • uaccess.h
  • Access to user space virtual memory
  • processor.h
  • Page size
  • User space process size
  • define TASK_SIZE (PAGE_OFFSET -
    (CONFIG_VMALLOC_SIZE 1024 1024)
    ARC_SOME_PADDING)
  • struct thread_struct architecture specific
    additions to the linux task ( struct task_struct
    )
  • init task and its initializations

11
Linux kernel initialization
  • TOPDIR/init/main.c
  • start_kernel()
  • asmlinkage void __init start_kernel(void)
  • char command_line
  • extern char saved_command_line
  • /
  • Interrupts are still disabled. Do necessary
    setups, then
  • enable them
  • /
  • lock_kernel()
  • printk(linux_banner)
  • setup_arch(command_line)
  • printk("Kernel command line s\n",
    saved_command_line)
  • parse_options(command_line)
  • trap_init()
  • init_IRQ()
  • sched_init()
  • softirq_init()

12
Linux kernel initialization
  • console_init()
  • sti()
  • calibrate_delay()
  • ifdef CONFIG_BLK_DEV_INITRD
  • if (initrd_start !initrd_below_start_ok
  • initrd_start lt min_low_pfn ltlt PAGE_SHIFT)
  • printk(KERN_CRIT "initrd overwritten (0x08lx lt
    0x08lx) - "
  • "disabling it.\n",initrd_start,min_low_pfn ltlt
    PAGE_SHIFT)
  • initrd_start 0
  • endif
  • mem_init()
  • kmem_cache_sizes_init()
  • pgtable_cache_init()
  • rest_init()

13
Linux kernel initialization
  • The first linux thread
  • static void rest_init(void)
  • kernel_thread(init, NULL, CLONE_FS CLONE_FILES
    CLONE_SIGNAL)
  • unlock_kernel()
  • current-gtneed_resched 1
  • cpu_idle()

14
Architecture support
  • arc/kernel/setup.c
  • setup_arch() Pseudo Code
  • Enable I / D caches
  • Parse commandline for architecture specific
    parameters
  • Probe for available memory
  • Register Boot memory (bootmem)
  • bootmap_size init_bootmem_node(NODE_DATA(0),
    start_pfn, min_low_pfn, max_low_pfn)
  • free_bootmem(PFN_PHYS(start_pfn),
    PFN_PHYS(size))
  • reserve_bootmem(PFN_PHYS(start_pfn),
    bootmap_size)
  • Initialize Paging paging_init()
  • arc/kernel/init_task.c
  • The init_task_union
  • Associated file_struct , fs_struct and mm_struct

15
Architecture support
  • arc/kernel/irq.c
  • Contains all of the interrupt handling and
    registering functionality
  • NR_IRQ macro defined to max number of interrupt
    types
  • init_IRQ() called from stat_kernel()
  • Initialize interrupt unit
  • Initialize / Copy vector table
  • Request an interrupt handler
  • int request_irq(unsigned int irq, void
    (handler)( int , void , struct pt_regs ),
    unsigned long flags, const char devname, void
    dev_id)
  • Free an interrupt handler
  • void free_irq(unsigned int irq, void dev_id)
  • Common interrupt handler and interrupt
    multiplexer
  • void process_interrupt(unsigned int irq, struct
    pt_regs fp)

16
Architecture support
  • arc/ kernel/time.c
  • Has the timer functionality to manage the
    heartbeat or jiffies of the linux kernel
  • Timer initialization time_init()
  • void __init time_init(void)
  • Setup / register irq handler
  • Initialize the system timer to interrupt at 100hz
    ( 1 tick every 10ms)
  • Timer interrupt handler
  • Call do_timer() - architecture independent
    function to handle system tick ( See
    TOPDIR/kernel/timer.c )
  • arc/kernel/semaphore.c
  • Use generic versions ( ARM, i386 ) initially
  • arc/kernel/sys_arc.c
  • Remains unchanged across most architectures

17
Architecture support
  • arc/proc/arc700/entry.S
  • System vector table
  • System call interface / entry
  • Switch from user to kernel stack
  • Renable exceptions/interrupt
  • Set up parameters (ABI)
  • Call system call through the syscall table
  • System call exit
  • Interrupt exit
  • Exception exit
  • Syscall table
  • System call wrappers passing the pt_regs
    pointer

18
Architecture MMU support
  • arc/mm/
  • Memory initializations
  • mem_init()
  • paging_init()
  • Cache handling
  • Keep caches turned off during initial porting
  • Translation lookaside buffers (TLB)
  • Software managed ?
  • ITLB/DTLB miss handlers
  • Software emulation of unsupported paging bits.
  • Page fault handling
  • do_page_fault() - main page fault handler
  • Major / minor page faults

19
Questions
  • Email - amit.bhor_at_codito.com
  • ARC linux arc-support_at_codito.com
Write a Comment
User Comments (0)
About PowerShow.com