Tuesday, May 2, 2023

Bootsect

Bootsect (bootsect.s) is 1 sector in length and loaded to memory location x07C00 (31,744B) by BIOS interrupt 13.  Bootsect runs in real mode which addresses 1MB (20 bit address. 1MB = 1,048,576B).  BIOS IVT is loaded in x00000 to x003FF by BIOS (256 interrupts with 4 bytes each total 1KB), followed by BIOS data (256B from x00400 to x004FF).  The interrupt service routine is 8KB in length and is loaded to x0E05B, which is 56KB after.  So the memory is not used from about 65KB and up to where BIOS is located at xFE000 for 8KB until the end of the real memory.

Once Bootsect is loaded and starts to run, it will load the next 2 sectors from the boot device into memory.  The 2 sectors contain the set up program (setup.s).

Before reading in setup.s, Bootsect firstly relocates itself from x07C00 (BOOTSEG at address ~32K) to x09000 (INITSEG at address 576K).  Bootsect the establishes the stack at x9FF00 (address ~655K) with ~63KB space from end of INITSEG.  

Bootsect uses interrupt x13h (disk service program) to load setup program to memory at address x90200 (512KB = 1 sector after bootsect.s) for 5 sectors (2.5KB or A00).  

Bootsect then loads the system modules into memory.  Bootsect uses interrupt x13h again and loads 240 sectors (120KB) into x10000 (address at 65K, after the BIOS IVT, BIOS data and IVT service routine).  As this takes some time to load so many sectors from floppy disk, Bootsect will display "Loading System...." message on the console.  System modules span from x10000 to x11E00 (up to address ~73K).

Lastly, bootsect inspects the root device number and record in at 01A964 (root_dev) in system data.  Bootsect than transfers the execution to the set up program at x90200.

Sunday, April 9, 2023

From BIOS to Bootsect

When one powers on a PC  with am Intel microprocessor, the core starts up in real address mode.  Real mode has a 20-bit address space (x00000 to xFFFFF) which is 1MB long.  The core initializes the code segment (cs) register to xFFFF and the IP to x0000.  This makes the core to start executing the memory location xFFFF0 which is a location in the BIOS.

BIOS first set up the interrupt vector table (IVT) in the first 1KB of memory (x00000 to x003FF).  The BIOS data, which is 256B long, is placed next and after the IVT (from x00400 to x004FF).  The interrupt service routine is placed between x0E05B to x0FFFE (near the 56KB mark from start of memory).  The IVT is essential for BIOS to load the boot sector into memory.

IVT has 256 entries of 4-bytes each.  Two bytes for the segment register value and 2 bytes for the offset.

BIOS invokes INT 19h using IVT.  INT 19h load disk 0, track 0 and sector 1 into x07C00 (about 31KB from start of memory).  The sector is 512B long and is called Bootsect.


Notes on C 2

 FIFO is byte-oriented.  One reads and writes based on number of bytes.  Message queue has a concept of message with a type attribute.  One can retrieve message based on type which could be out of arrival order.

Shared memory needs to have a backing file.


Sunday, March 12, 2023

Notes on C

 Function is a callable block in assembly.  It means the block is marked with a label at the beginning so it can be jumped to symbolically.

Function defined with implementation details placed before (function) main served double up as a function declaration (signature that other function can call accordingly).

The main function is called by one of the exec family call and value is return to exec call when the C program ends.

Command line can be passed to the main function as argument.  The argument are passed as an array of string.  It can be declared as char *argv[] or char **argv.

There is no boolean type in C.  Integer (int) is used to represent false with a value of 0.  1 or any positive value represent true.  While (1) represent an infinity loop with a always true condition.

Condition used in control statement (for, while, do, switch etc) must be enclosed by parenthesis.

For SWITCH statement, execution will start from a matching case statement and continue from there straight until it reach a BREAK or end of SWITCH.  In other words, it will also execute codes in ensuing cases that following the matching case.

Array variable is a type of pointer.  It points to the first item of an array.  So is a function name.  It can be passed as a pointer as an argument to another function.

Pointer arithmetic convert an offset to its product with the item size.  For example, arr+3 = arr+(3*4) for an array of integer.  The compiler will perform the offset arithmetic on behalf of human.

There are 4 storage classes.  extern and static are for both function and variable.  auto and register are applicable to variable only.  

Variable is defined when it is assigned a value.  Variable is declared when no value is assigned.  There can only be 1 definition statement for variable in a program but there could be many declaration.

int a = 10; /*definition*/

int a; /*declaration*/

Variable defined outside a block is either static or extern (default).

Variable defined within a block is either register or auto (default).

When a variable is defined as extern or static, it exists through out the program's life time.  

A static variable declared in a function (block scope) is initialized once even the function may be called repeatedly.  A static variable has default value 0 if it is not initialized.

A static variable declared outside a function (outside a block) has scope from the point of declaration to the end of the file containing the declaration code.  It is not visible outside the file (i.e. in other program files that may be compiled together).

A extern variable has global scope if it is defined (initialized) in one file and is declared in other files that require access to the variable (and that are to be compiled together).

register class is typically not required anymore as compiler would optimize the code by assigning variables to register for efficiency.  If compiler deems no register is available, variable defined as register will be treated as auto.

volatile is not a storage class.  When variable is defined as volatile, the programmer informed the compiler to avoid optimize it by assigning it to register.  For example, if a variable is to be updated by ISR (e.g. placement for received byte), the variable needs to be in memory rather than register.

Function can be defined as static or extern, but not auto or register.  A static function is visible within the file containing the function.  It is similar to private function in C++,  A extern function is visible outside the file it is defined when the other file declares the function.



Saturday, February 25, 2023

java class in a class

A class defined in another class is called a nested class when it has the static keyword and inner class if it does not has the static keyword. A inner class does not has a reference to its outer class but an inner class has. In other words, a inner class can access the outer class instance variable

Monday, April 30, 2018

Scarborough Fair

The main melody is from an old song. The canticle refers to the counterpoint added to harmonize the main melody.

In Medieval times, the herbs mentioned in the song represented virtues that were important to the lyrics. Parsley was comfort, sage was strength, rosemary was love, and thyme was courage.

The things the singer asks for in Scarborough Fair are all impossible. A shirt with no seams. An acre of land between the sea and the seastrand (beach). To harvest grain with a leather blade (leather isn't very sharp), and bundle the stalks with heather (a fragile twig-like flower; doesn't make for very good rope or string).

Saturday, March 3, 2018

JDBC Connection

The early version of JDBC provided a Driver class with a GetConnection method for application.  Underneath Driver uses Java Socket class to get a connection to the database.  Later, DriverManager class provide the connection using an url.  Using a generic interface saved the application the need to know which specific driver to use.  The connection returned is a physical connection (a socket) which is adequate for a 2-tier client-server architecture as each client will create and use its own connection and seldom sharable.

JDBC v2.0 uses DataSource to support Java Transaction API and a 3-tier architecture.  An intermediate layer (application server) sits between client and the database.  DataSource returns a logical connection from a connection pool which improves performance by avoiding set up time for every JDBC connection request.